01 · Question
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
02 · Analysis
Invariant: mins stores every new or tied minimum. Use <= on push so duplicate minima survive one pop. For example, push 2 twice and pop once: the minimum must still be 2. pop, top, and getMin require a nonempty stack. Push/pop are amortized O(1) with dynamic arrays; top/getMin are O(1). Space is O(n).
03 · Solution