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

0

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
monotonic stack
histograms
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported