Largest Rectangular Display Area Under an Uneven Shelf Skyline
Last updated: November 29, 2026
Quick Overview
A wall of shelf columns has uneven free vertical space, given as one height per unit-wide column. Find the area of the largest rectangular promotional display that fits entirely within the free space.
Walmart Labs
November 29, 20260
0
0 solved
A wall of shelf columns has uneven free vertical space, given as one height per unit-wide column. Find the area of the largest rectangular promotional display that fits entirely within the free space.
A store layout framing of the largest rectangle in a histogram, in the spirit of planograms used across Walmart stores. Walmart Labs onsite interviewers use it to test monotonic stack reasoning, especially computing each bar's left and right extent correctly.
What the Interviewer Expects
- Explain that every optimal rectangle is limited by its shortest column
- Use a stack of indices with non-decreasing heights
- Compute width from the new stack top after popping
- Use a zero sentinel to flush remaining columns
- Validate against brute force on small cases
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 all-free rectangle in a 2D grid of shelf cells?
- How would you also return the column range of the best display?
- What if columns have different widths?
- Can you do it with precomputed left and right smaller arrays instead?
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 non-negative integer heights, one per column of width 1. Output: the largest area height * width of a rectangle sitting on the floor whose height does not exceed any column it spans. ...
High-Level Design
In the best rectangle, some column is the shortest, and the rectangle extends from that column left and right until a strictly shorter column. So for each column we need its nearest shorter neighbors ...