Solve Reported OA Coding Problems
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This prompt evaluates algorithmic problem-solving skills across grid-based ordering constraints, array pair-sum identification, and minimum-difference computation, testing knowledge of data structures, time/space complexity, and correctness conditions.
Part 1: Remove Blocks in a Grid
Constraints
- `0 <= m, n <= 200`
- Each cell is either `0` or `1`
- If `m > 0`, all rows have the same length
Examples
Input: ([[1, 1, 0], [1, 0, 1]],)
Expected Output: [(0, 1), (0, 0), (1, 2), (1, 0)]
Explanation: Within each row, blocks must be removed from right to left. The shown output processes row 0 first, then row 1.
Input: ([[1, 0, 1, 1]],)
Expected Output: [(0, 3), (0, 2), (0, 0)]
Explanation: In a single row, only the rightmost remaining block can be removed at each step.
Hints
- Think about one row at a time. In what order must the `1`s in a single row be removed?
- Rows do not affect each other, so once each row order is known, you can combine the rows in any convenient way.
Part 2: Find Two Indices for a Target Sum
Constraints
- `0 <= len(nums) <= 100000`
- `-10^9 <= nums[i], target <= 10^9`
- Indices in the answer must be distinct
Examples
Input: ([2, 7, 11, 15], 9)
Expected Output: [0, 1]
Explanation: Because `2 + 7 = 9`.
Input: ([3, 2, 4], 6)
Expected Output: [1, 2]
Explanation: Because `2 + 4 = 6`.
Hints
- While scanning from left to right, ask what complement value you would need to have seen already.
- A hash map from value to index can find that complement in O(1) average time.
Part 3: Compute the Minimum Gap
Constraints
- `0 <= len(nums) <= 200000`
- `-10^9 <= nums[i] <= 10^9`
Examples
Input: ([3, 8, 15, 17],)
Expected Output: 2
Explanation: The smallest difference is `17 - 15 = 2`.
Input: ([1, 5, 3, 19, 18, 25],)
Expected Output: 1
Explanation: After sorting, `18` and `19` are adjacent and differ by `1`.
Hints
- After sorting, the closest pair must appear next to each other.
- Be careful with the edge case where the array has fewer than two numbers.