← All problems
Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1) time. The challenge is getMin: think about what auxiliary information must be maintained on each push.
Complexity
Time O(1) all ops, Space O(n)
Common pitfalls
- Popping the min tracking on duplicate mins
- Recomputing min on pop (O(n))
Your solution
Log in to save your code and track progress.