Reported May 2026
Ziplinemonotonic stack

Largest Rectangle in Histogram

Reported by candidates from Zipline's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Zipline OA. Under 2s to a working solution.
Founder's read

Zipline reportedly put Largest Rectangle in Histogram in front of candidates in May 2026, and the whole problem hinges on one data structure: a monotonic stack. If you're taking this OA in the next day or two, that's the thing to lock in. The brute force is easy to write and it will time out on 100000 bars. The stack version is about fifteen lines once you see it. If your mind goes blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you the solution as a safety net. Know the idea first, though.

The problem

Given an integer array heights representing a histogram, where every bar has width 1, return the area of the largest rectangle that can be formed using one or more consecutive bars.

Function
largestRectangleArea(heights: int[]) → int

Examples
Example 1
heights = [2,1,5,6,2,3]
return = 10
The bars of heights 5 and 6 form a rectangle of height 5 and width 2.
Example 2
heights = [2,4]
return = 4
The best area is 4, achieved either by the second bar alone or by both bars at height 2.
Example 3
heights = [0]
return = 0
The only bar has height 0, so no positive-area rectangle exists.

Constraints
1 <= heights.length <= 100000.
0 <= heights[i] <= 10000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a stack of indices whose bar heights are increasing. Walk through the array, and when the current bar is shorter than the bar on top of the stack, pop it. That popped bar's height is the rectangle height. The right edge is the current index, and the left edge is the new stack top plus one, or zero if the stack is empty. Width is right minus left minus one. Append a sentinel height of 0 at the end so everything flushes out. The common pitfall is the width calculation after popping, which causes off-by-one errors. Another is forgetting leftover bars at the end. Each index is pushed and popped once, so it runs in O(n), which matters at 100000 elements. Test with [2,1,5,6,2,3] expecting 10 and [0] expecting 0. If the width math slips under pressure, StealthCoder is the hedge during the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Largest Rectangle in Histogram cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as largest rectangle in histogram. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Zipline's OA.

Zipline reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Largest Rectangle in Histogram FAQ

What's the trick to Largest Rectangle in Histogram?+

Use a monotonic increasing stack of indices. When a shorter bar arrives, pop taller bars and compute the area using each popped height. The width spans from the new stack top plus one to the current index minus one. It's O(n) because each bar is pushed and popped once.

How hard is this problem really for an OA?+

It's a hard-tier problem, but only because the stack idea isn't obvious. Once you know the pattern, the code is short. The brute force O(n^2) approach is simple, but with up to 100000 bars it likely won't pass, so you need the stack.

Why does my solution fail on the last bars?+

You probably didn't flush the stack at the end. Bars that never meet a shorter right neighbor stay on the stack. Fix it by appending a 0 height sentinel to the array, or by running a cleanup loop after the main pass that pops everything using n as the right edge.

How do I handle the width when the stack is empty?+

If the stack is empty after popping, the popped bar was the shortest so far, so the rectangle extends from index 0 to the current index. Width equals the current index. Otherwise width is the current index minus the new stack top minus 1.

How do I prepare for this in 48 hours?+

Write the monotonic stack solution from scratch three times without looking. Trace [2,1,5,6,2,3] by hand and confirm 10. Then test edge cases: a single bar, all equal heights, strictly increasing, strictly decreasing, and zeros. That covers nearly every bug people hit.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Zipline.

OA at Zipline?
Invisible during screen share
Get it