Largest Open Rectangle of Parking Spots in a Driver Hub Lot
Last updated: November 29, 2026
Quick Overview
A driver hub's parking lot is a grid of 1s (free spot) and 0s (occupied or blocked). Return the area of the largest axis-aligned rectangle made entirely of free spots, used to reserve a block for a fleet of vehicles.
Uber
November 29, 20260
0
0 solved
A driver hub's parking lot is a grid of 1s (free spot) and 0s (occupied or blocked). Return the area of the largest axis-aligned rectangle made entirely of free spots, used to reserve a block for a fleet of vehicles.
An Uber onsite grid problem that hides a monotonic stack: treat each row as the base of a histogram. The interviewer wants you to reach O(rows x cols) and to explain the largest rectangle in a histogram subroutine carefully.
What the Interviewer Expects
- Builds per-column heights of consecutive free cells row by row
- Applies a largest-rectangle-in-histogram routine per row
- Uses a monotonic increasing stack with a sentinel
- Computes widths correctly when popping
- Explains why the total is O(rows x cols)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you find the largest square instead?
- What if some spots can be freed at a cost and you have a budget?
- How would you return the rectangle's coordinates?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of lists of 0/1, possibly empty. Output: max area as an int. Grid up to 500 x 500, so enumerating all rectangles is far too slow....
High-Level Design
For each row, heights[c] is the number of consecutive free cells ending at that row in column c (reset to 0 on a blocked cell). The best rectangle whose bottom edge sits on this row is the largest r...