Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Implement the MinStack class:
push(val) - pushes the element onto the stackpop() - removes the top elementtop() - returns the top elementgetMin() - returns the minimum elementInput: push(-2) push(0) push(-3) getMin() pop() top() getMin() Output: -3 0 -2
For the runner, simulate operations inside code and print outputs line by line.
No submissions yet.
Discuss auxiliary stack approach vs encoding values.