Largest Rectangle in Histogram
LeetCode 84 • Hard • Stack
Input: heights = [2,1,5,6,2,3] → Output: 10. Monotonic stack: pop while stack top > current, area = height[pop] × width.
TimeO(n)
SpaceO(n)
i: —
stack: []
maxArea: 0
Stack indices
Current area
i—
stack[]
maxArea0
Ready
Press Play. Monotonic stack: pop while heights[stack[-1]] > heights[i]. Area = height[pop] × width.