Largest Banner That Fits Above a Masonry Column Skyline
Last updated: November 29, 2026
Quick Overview
After laying out a masonry grid, each column has some free vertical space left at the bottom of the viewport. Given those free heights for adjacent equal-width columns, find the largest rectangular banner (area in column-units times pixels) that fits, and which columns it spans.
0
0
0 solved
After laying out a masonry grid, each column has some free vertical space left at the bottom of the viewport. Given those free heights for adjacent equal-width columns, find the largest rectangular banner (area in column-units times pixels) that fits, and which columns it spans.
Pinterest's uneven masonry columns leave ragged gaps that product teams sometimes want to fill with a module such as a shopping carousel or a prompt. This is the largest rectangle in a histogram in disguise; the interviewer checks the monotonic stack invariant and the width calculation when popping.
What the Interviewer Expects
- Maps the layout problem to largest rectangle in a histogram
- Maintains a stack of indices with increasing heights
- Computes width using the new stack top as the left boundary
- Uses a sentinel zero at the end to flush the stack
- Returns the span, not only the area
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 require the banner to span at least 2 columns?
- What if the free space is a 2D grid of booleans instead of column heights?
- How would you update the answer incrementally as new Pins load into columns?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- heights: non-negative integers, one per adjacent column.
- The banner is a rectangle spanning a contiguous range of columns with height at most the minimum free height in that range.
- Output (area,...
High-Level Design
For each column as the limiting (shortest) column, the best rectangle extends left and right until a strictly shorter column. A stack of increasing heights finds both boundaries in one pass: when the ...