Minimum stack · Compiler
Minimum stack
Maintain an initially empty stack of integers. PUSH x adds x at the top. POP removes the top value if there is one. MIN reports the smallest value currently in the stack. Support MIN in constant time.
- Input
- The first line contains the command count q (1 <= q <= 1000). Each of the next q lines contains PUSH x, POP, or MIN. Values range from -1000 to 1000. There is at least one MIN.
- Output
- For each MIN, print the current minimum on its own line, or EMPTY if the stack is empty.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…