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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Monotonic stack
Histogram
Matrix
Dynamic programming
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported