Largest Rectangle in Histogram
A hard-tier problem at 47% community acceptance, tagged with Array, Stack, Monotonic Stack. Reported in interviews at Zynga and 25 others.
Largest Rectangle in Histogram is a hard array problem that trips up even experienced engineers in live assessments. It appears across 26+ companies including Amazon, Flipkart, and Capital One. The naive brute force approach feels right until you hit time limits, and the monotonic stack pattern isn't obvious unless you've seen it. If this lands in your OA and you blank on the trick, StealthCoder solves it in seconds, invisible to the proctor. With a 47% acceptance rate, it's a heavy hitter.
Companies that ask "Largest Rectangle in Histogram"
Largest Rectangle in Histogram is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe problem asks you to find the largest rectangular area in a histogram given an array of heights. Brute force iterates through each bar, expands left and right until the height drops, and tracks the max area. That's O(n^2) and fails on large inputs. The actual solution uses a monotonic stack to process bars in one pass, tracking indices of bars in increasing height order. When you hit a shorter bar, you pop the stack and calculate rectangles. This O(n) approach is the only viable path at scale. The trick isn't algorithmic sophistication, it's recognizing the stack pattern. StealthCoder is your hedge if the monotonic stack insight doesn't click during your assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Largest Rectangle in Histogram recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Largest Rectangle in Histogram interview FAQ
Is this really asked at Amazon and Flipkart?+
Yes. It appears in interview reports from both companies and nine others in the top tier. It's a classic hard-tier array problem. If you're prepping for either, this is a high-probability target.
Why is the acceptance rate so low?+
At 47%, most candidates either timeout on brute force or can't construct the monotonic stack logic under pressure. The pattern isn't intuitive if you haven't studied it. Prep specifically for the stack approach.
What's the actual trick?+
Maintain a stack of bar indices in increasing height order. When you see a shorter bar, pop and calculate the rectangle area for each popped bar. The width extends from the current bar to the bar before the new stack top. That's the entire algorithm.
Does this relate to Daily Temperatures or other stack problems?+
Yes. All three topics listed (Array, Stack, Monotonic Stack) apply here. If you've solved Daily Temperatures or similar monotonic stack problems, you recognize the pattern faster. Same data structure, different application.
How much time should I allocate in the OA?+
If you see this and know the stack pattern, 10 to 15 minutes. If you don't recognize it and default to brute force, you'll TLE and burn 30+ minutes. Know the pattern before the assessment.
Want the actual problem statement? View "Largest Rectangle in Histogram" on LeetCode →