โ Back to the stacks page
Min / Max Stack
A stack that also answers "what is the current minimum?" in O(1) by carrying the running extreme alongside every entry.
What to know
- Store (value, minSoFar) pairs, or keep a second stack of minimums.
- Pop keeps both stacks in sync automatically.
- Same trick generalizes to max, and to queues via two stacks.
In the wild: Sliding-window financial stats, constraint tracking in games, interpreter scopes.
Algorithms to reach for
MinStack ops
O(1)push/pop/top/getMin all O(1) (LeetCode 155)
Queue from two stacks
O(1) amortizedAmortized O(1) FIFO using LIFO parts
Practice problems โ with full guides
Each problem has its own page: progressive hints, how to approach it, and the full solution.