Monotonic Stack
Interactive Visualization: Next Greater Element & Largest Rectangle in Histogram
Configuration
Mode:
Next Greater Element
Largest Rectangle (histogram)
Array:
Load
Random
Play
Step >
Pause
Reset
Speed:
Visualization
Stack
idle
scan (current i)
on stack
just pushed
just popped
resolved / rectangle
Step
READY
Press
Play
to start, or
Step >
to advance one operation.
Statistics
0
Step
-
Index i
0
Stack Depth
0
Max Depth
0
Pushes
0
Pops
-
Best Area
0
N
Big-O
Metric
Value
Time
O(n)
Space
O(n)
Pushes total
n
Pops total
≤ n
Worst burst
O(n) once
Log