Implement Three Assessment Functions
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This multi-part problem evaluates competency in geometric bounds computation and coordinate arithmetic, record filtering and aggregation under threshold constraints, and constant-time arithmetic reasoning for constrained movement across discrete grids.
Part 1: Compute Coordinate Bounds
Constraints
- 1 <= len(points) <= 200000
- -10^9 <= x, y <= 10^9
Examples
Input: ([(1, 2), (3, 5), (-1, 4)],)
Expected Output: [-1, 2, 4, 3]
Explanation: minX = -1, minY = 2, maxX = 3, and maxY = 5.
Input: ([(7, -3)],)
Expected Output: [7, -3, 0, 0]
Explanation: A single point forms a zero-width, zero-height bounding box.
Input: ([(-5, -2), (-1, -8), (-3, -4)],)
Expected Output: [-5, -8, 4, 6]
Explanation: minX = -5, minY = -8, maxX = -1, and maxY = -2.
Input: ([(0, 0), (0, 5), (2, 5), (2, 0)],)
Expected Output: [0, 0, 2, 5]
Explanation: The points span x from 0 to 2 and y from 0 to 5.
Hints
- Track the smallest and largest x and y values in one pass.
- If there is only one point, both width and height are 0.
Part 2: Find the Highest Eligible Score
Constraints
- 0 <= len(records) <= 200000
- Each name is a string
- -10^9 <= score, threshold <= 10^9
Examples
Input: ([('Alice', 70), ('Bob', 85), ('Cara', 85), ('Dan', 90)], 85)
Expected Output: 'Bob'
Explanation: Dan is filtered out, and Bob and Cara tie at 85. Bob appears first.
Input: ([('A', 10), ('B', 20)], 5)
Expected Output: None
Explanation: Both scores are above the threshold, so no record is eligible.
Input: ([], 100)
Expected Output: None
Explanation: An empty list has no eligible record.
Input: ([('Solo', 50)], 50)
Expected Output: 'Solo'
Explanation: The only record is eligible and must be returned.
Input: ([('Mia', -2), ('Noah', -5), ('Oli', -2)], -2)
Expected Output: 'Mia'
Explanation: Mia and Oli tie for the highest eligible score of -2, and Mia appears first.
Hints
- Scan once and keep track of the best eligible score seen so far.
- To preserve the first name on ties, only replace the answer when you find a strictly larger eligible score.
Part 3: Move Across a Server Grid Efficiently
Constraints
- 1 <= width, height <= 10^18
- 0 <= x < width
- 0 <= y < height
- direction is one of 'U', 'D', 'L', 'R', 'UR', 'DR', 'UL', 'DL'
- 0 <= maxAttempts <= 10^18
Examples
Input: (1, 1, 'UR', 5, 4, 10)
Expected Output: [2, 0]
Explanation: From (1, 1), moving up-right is blocked after 1 step because the next move would leave the top edge.
Input: (3, 2, 'DL', 8, 6, 2)
Expected Output: [1, 4]
Explanation: Two down-left moves are possible, and maxAttempts is 2.
Input: (0, 0, 'UL', 10, 10, 5)
Expected Output: [0, 0]
Explanation: The very first move would leave the grid, so no movement occurs.
Input: (0, 0, 'R', 3, 3, 0)
Expected Output: [0, 0]
Explanation: With zero allowed attempts, the starting coordinate is returned.
Input: (5, 5, 'D', 10, 1000000000, 1000000000000)
Expected Output: [5, 999999999]
Explanation: You can move down until the last row, which is reached long before maxAttempts runs out.
Hints
- Convert direction into a step pair (dx, dy).
- Find how many steps you can take before hitting an x-boundary and a y-boundary, then take the minimum of those values and maxAttempts.