Monotonic Stack

Interactive Visualization: Next Greater Element & Largest Rectangle in Histogram

Configuration

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

MetricValue
TimeO(n)
SpaceO(n)
Pushes totaln
Pops total≤ n
Worst burstO(n) once

Log