Solve remembered OA coding tasks
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This set of problems evaluates skills in data aggregation and ordering (identifying top averages), computational geometry and extrema calculation (axis-aligned bounding rectangle), and grid constraint validation and consistency checking (partially filled 9x9 number board).
Top Three Companies by Average Stock Price
Constraints
- 0 <= number of companies
- Each price list has at least one price
- Prices are integers (or floats)
- Company names are unique strings
Examples
Input: ({'A': [10, 20, 30], 'B': [5, 5, 5], 'C': [100], 'D': [40, 40]},)
Expected Output: ['C', 'D', 'A']
Explanation: Averages: A=20, B=5, C=100, D=40. Top three by average: C(100), D(40), A(20).
Input: ({'X': [10], 'Y': [10]},)
Expected Output: ['X', 'Y']
Explanation: Both average 10; fewer than three companies, so return all, tie-broken by name: X then Y.
Input: ({'Apple': [1, 2, 3]},)
Expected Output: ['Apple']
Explanation: Only one company, return it.
Input: ({'Z': [50, 50], 'A': [50], 'M': [50, 50, 50], 'B': [10]},)
Expected Output: ['A', 'M', 'Z']
Explanation: A, M, Z all average 50 (tie), B averages 10. Top three are the three tied at 50, ordered lexicographically: A, M, Z.
Input: ({},)
Expected Output: []
Explanation: No companies, return empty list.
Hints
- Compute the average for every company first.
- Sort by average descending, then by company name ascending for ties.
- Slice the first three entries; if there are fewer than three companies, the slice naturally returns all of them.
Bounding Rectangle of a Set of Points
Constraints
- 1 <= number of points
- Each point is a pair [x, y] of integers
- Coordinates may be negative
Examples
Input: ([[1, 2], [3, 4], [5, 0]],)
Expected Output: [1, 0, 4, 4]
Explanation: min_x=1, min_y=0, max_x=5, max_y=4 -> width=4, height=4.
Input: ([[0, 0]],)
Expected Output: [0, 0, 0, 0]
Explanation: Single point: corner at (0,0), zero width and height.
Input: ([[-3, -7], [2, 5], [-1, 0]],)
Expected Output: [-3, -7, 5, 12]
Explanation: min_x=-3, min_y=-7, max_x=2, max_y=5 -> width=5, height=12. Handles negatives.
Input: ([[10, 10], [10, 10], [10, 10]],)
Expected Output: [10, 10, 0, 0]
Explanation: All points identical: zero-size rectangle at (10,10).
Input: ([[2, 9], [2, 1]],)
Expected Output: [2, 1, 0, 8]
Explanation: Same x for both points -> width 0; y spans 1..9 -> height 8.
Hints
- Track the minimum and maximum x separately, and the minimum and maximum y separately.
- Width is max_x - min_x; height is max_y - min_y.
- A single point gives width and height of 0.
Validate a Partially Filled 9x9 Number Board
Constraints
- board is exactly 9 rows by 9 columns
- each cell is a single character '1'-'9' or '.'
- the board need not be complete or solvable
Examples
Input: ([['5','3','.','.','7','.','.','.','.'],['6','.','.','1','9','5','.','.','.'],['.','9','8','.','.','.','.','6','.'],['8','.','.','.','6','.','.','.','3'],['4','.','.','8','.','3','.','.','1'],['7','.','.','.','2','.','.','.','6'],['.','6','.','.','.','.','2','8','.'],['.','.','.','4','1','9','.','.','5'],['.','.','.','.','8','.','.','7','9']],)
Expected Output: True
Explanation: The canonical valid Sudoku starting board: no row, column, or box has a repeat.
Input: ([['8','3','.','.','7','.','.','.','.'],['6','.','.','1','9','5','.','.','.'],['.','9','8','.','.','.','.','6','.'],['8','.','.','.','6','.','.','.','3'],['4','.','.','8','.','3','.','.','1'],['7','.','.','.','2','.','.','.','6'],['.','6','.','.','.','.','2','8','.'],['.','.','.','4','1','9','.','.','5'],['.','.','.','.','8','.','.','7','9']],)
Expected Output: False
Explanation: The 5 at (0,0) was changed to 8; now column 0 has two 8's (rows 0 and 3) and the top-left box also has two 8's. Invalid.
Input: ([['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.']],)
Expected Output: True
Explanation: Completely empty board: trivially valid.
Input: ([['5','5','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.']],)
Expected Output: False
Explanation: Two 5's in the same row (cells (0,0) and (0,1)). Invalid.
Input: ([['1','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','1','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.'],['.','.','.','.','.','.','.','.','.']],)
Expected Output: False
Explanation: Two 1's in different rows/columns but both in the top-left 3x3 box (cells (0,0) and (2,2)). Invalid by the box rule.
Hints
- Use one set per row, one per column, and one per 3x3 box to track seen digits.
- Map cell (r, c) to its box index with (r // 3) * 3 + (c // 3).
- Skip '.' cells; on any duplicate insertion into a row/column/box set, the board is invalid.