Design a stack that supports push, pop, top, and retrieving the minimum element — all in O(1) time.
The trick: maintain two stacks:
min(val, current_min)This way, getMin() just peeks at the top of the min stack — always O(1)!
ms.getMin()
-3
ms.top()
0
ms.getMin()
-2