A reactor console maintains a vertical stack of control-rod readings. It processes a stream of q operations, each one of:
PUSH v — place a reading v (an integer) on top of the stack.POP — remove the reading currently on top. It is guaranteed the stack is non-empty.MIN — report the smallest reading currently anywhere in the stack. It is guaranteed the stack is non-empty.Process the operations in order.
Line 1: an integer q, the number of operations.
Next q lines: one operation each, in the forms above.
For every MIN operation, in order, print one line containing the current minimum reading.
POP and MIN acts on a non-empty stack.Example 1
Input
5 PUSH 5 PUSH 2 MIN POP MIN
Expected
2 5
Explanation
After pushing 5 then 2 the stack is [5, 2] and MIN prints 2. POP removes 2 leaving [5], and MIN prints 5.
Example 2
Input
3 PUSH -4 PUSH 7 MIN
Expected
-4
Explanation
The stack holds [-4, 7]; the smallest reading is -4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →