dsa · medium
Min Stack
GreyOrangeStackDesign
Implement a stack that also returns the current minimum in O(1).
Methods
push(val)push onto the stackpop()remove the top (never called on empty)top()the top value (never called on empty)getMin()the smallest value still in the stack, not a pop
Fill in the MinStack class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.
**Example**
`` MinStack() → null push(-2) → null push(0) → null push(-3) → null getMin() → -3 pop() → null top() → 0 getMin() → -2 ``
Constraints
Calls <= 3 * 10^4
Examples
Example 1
Input: ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] Expected: [null,null,null,null,-3,null,0,-2]