Reported September 2026
Tekionmonotonic stack

Largest Rectangle in Histogram

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

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

Tekion reported this one in September 2026, and the input size is the whole story. With up to 100000 bars, the obvious approach of trying every pair of start and end bars and tracking the minimum height is O(n^2) and dies on large inputs. This is Largest Rectangle in Histogram, and the real answer is a monotonic stack that finishes in one pass. If you've got an OA invite and 48 hours, learn that one idea cold. StealthCoder sits invisibly on your screen during the live assessment as a safety net if the stack logic slips away mid-test.

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: every optimal rectangle is limited by some bar's height. For each bar, you want the nearest shorter bar on the left and on the right. The width between them times that height is a candidate area. A monotonic stack of increasing heights finds both in one pass. Keep indices on the stack. When the current bar is shorter than the top, pop it, use it as the height, and compute width from the new top of stack to the current index. Append a sentinel bar of height 0 at the end so everything flushes. The common pitfall is the width formula. If the stack is empty after popping, the width is the full current index, not index minus one. Another is forgetting the final flush, which misses rectangles that extend to the right edge. StealthCoder is your hedge in the live OA if you blank on the pop logic, but the pattern is only about ten lines once it clicks.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

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 Tekion's OA.

Tekion reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Largest Rectangle in Histogram FAQ

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

Use a monotonic increasing stack of indices. When a bar is shorter than the stack top, pop and treat the popped bar as the limiting height. Width runs from the new stack top plus one to the current index minus one. One pass, O(n) time.

Why does brute force fail here?+

The constraints allow 100000 bars. Checking every start and end pair is about 5 billion operations at that size, which is far too slow. You need a linear approach, and the stack gives you that by finding each bar's boundaries once.

How do I handle the width calculation correctly?+

After popping, if the stack is empty, width equals the current index, since the popped bar extended all the way to the left edge. Otherwise width is current index minus new top minus 1. Test this on [2,4] and [2,1,5,6,2,3] before the OA.

What edge cases should I test?+

Test a single bar like [0], which returns 0. Test strictly increasing heights, where nothing pops until the end, so you need the sentinel or a final flush. Also test equal adjacent heights and all zeros. These catch most off-by-one and missing-flush bugs.

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 you get 10. Then do one related stack problem like next smaller element. The pattern is small, so repetition beats reading more theory.

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

OA at Tekion?
Invisible during screen share
Get it