Largest Rectangular Banner Spanning Adjacent Warehouse Racks
Last updated: November 29, 2026
Quick Overview
A row of adjacent racks of width 1 has heights given by an array. A rectangular safety banner must be hung flat against consecutive racks and cannot extend above any rack it covers. Return the largest possible banner area.
Amazon
November 29, 20260
0
0 solved
A row of adjacent racks of width 1 has heights given by an array. A rectangular safety banner must be hung flat against consecutive racks and cannot extend above any rack it covers. Return the largest possible banner area.
The largest rectangle in a histogram, framed as a facilities problem in the style of Amazon onsite rounds. Interviewers look for the monotonic stack solution, a precise explanation of the width computed on each pop, and the sentinel trick to flush the stack.
What the Interviewer Expects
- Explain the O(n^2) expand-around-each-bar approach
- Introduce a monotonic increasing stack of indices
- Compute width correctly when popping
- Use a sentinel to flush remaining bars
- Mention the extension to maximal rectangles in a binary matrix
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-ones rectangle in a binary grid?
- How would you return the start and end racks?
- What changes if banners may be slanted?
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: list of non-negative ints, possibly empty. Return the max area as an int....
High-Level Design
For each bar, the best rectangle using that bar's full height extends left and right until a shorter bar. A stack of indices with increasing heights finds both boundaries: when a bar shorter than the ...