Stack with Minimum
Easy
data-structures
Amazon
Google
Apple
Implement a stack that supports push, pop, and retrieving the minimum element in O(1) time.
Example
stack = MinStack()
stack.push(3)
stack.push(1)
stack.push(2)
stack.get_min() # => 1
stack.pop() # => 2
stack.get_min() # => 1
Test Cases
Python Editor
Output
Click "Run" to see results...