155. Min Stack
Practice Min Stack for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a stack that supports push, pop, top, and retrieving the minimum element with getMin, each in O(1) time.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["MinStack","push","push","push","getMin","pop","top","getMin"]
[[],[-2],[0],[-3],[],[],[],[]]
-> [null,null,null,null,-3,null,0,-2]
Constraints
pop,topandgetMinare only called on a non-empty stack