Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

30:00

Min Stack
medium
Topics
Companies

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Example 1:
Input: {"commands":["MinStack","push","push","push","getMin","pop","top","getMin"],"values":[[],[-2],[0],[-3],[],[],[],[]]}
Output: [null,null,null,null,-3,null,0,-2]
Constraints:
  • 231val2311-2^{31} \leq \text{val} \leq 2^{31} - 1

  • Operations pop, top, and getMin are always called on non-empty stacks.

  • At most 3×1043 \times 10^4 calls in total to push, pop, top, and getMin.

Input
arr ={"commands":["MinStack","push","push","push","getMin","pop","top","getMin"],"values":[[],[-2],[0],[-3],[],[],[],[]]}

Init stacks

Op:

init
Main Stack
Min Stack
Variables
No variables to display
DepthFunction Call
Stack empty
0/7