Largest Empty Rectangle on an iPad Home Screen Icon Grid
Last updated: November 29, 2026
Quick Overview
An iPad home screen is a grid where 1 marks a cell occupied by an icon or widget and 0 marks a free cell. Return the area of the largest axis-aligned rectangle of free cells, which is where the largest new widget could be placed.
Apple
November 29, 20260
0
0 solved
An iPad home screen is a grid where 1 marks a cell occupied by an icon or widget and 0 marks a free cell. Return the area of the largest axis-aligned rectangle of free cells, which is where the largest new widget could be placed.
Widget placement on iPadOS is a natural framing for the maximal rectangle problem. The interviewer checks that you reduce each row to a histogram of free heights and apply the largest-rectangle-in-histogram monotonic stack.
What the Interviewer Expects
- Build per-row histograms of consecutive free cells above
- Solve largest rectangle in a histogram with a monotonic increasing stack
- Use a sentinel to flush the stack at the end of each row
- Explain O(rows * cols) time
- Discuss restricting to standard widget sizes
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
- Widgets come only in fixed sizes such as 2x2, 2x4 and 4x4; can the largest fit be found faster?
- Return the rectangle's coordinates, not just its area.
- Find the largest free square instead.
- Icons can be moved; what is the fewest moves to fit a 4x4 widget?
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: grid as a list of lists of 0 and 1. Output: the largest area of a rectangle containing only 0s. Empty grid returns 0....
High-Level Design
For each row, heights[c] is the number of consecutive free cells ending at that row in column c; it resets to 0 at an occupied cell. The best rectangle whose bottom edge lies on this row is the larg...