Loading...
Loading...
Loading...
Build a stack that can report its smallest value at any time. Commands: push x, pop (removes the top), top (prints the top) and min (prints the smallest value in the stack). pop, top and min are only given when the stack is not empty.
Example 1
Input
7 push 5 push 3 push 7 min pop pop min
Output
3 5
Prints 3 and then 5.
Example 2
Input
3 push -2 top min
Output
-2 -2
Try the problem first. Open one hint at a time.
Keep a second stack with the smallest value so far at each depth.
Pop from both stacks together.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor