Pattern Recognition Drill
Medium Stacks & Queues
The Problem
Design a stack that supports push, pop, and getMin in O(1).
What approach would you use?
Think about it before scrolling down.
Store (value, current_min) pairs. On push, new_min = min(val, top.min). O(1) for all operations.
Common Trap
Tracking a single min variable breaks on pop — you lose the previous minimum.