Standard Bar Stack and Queues · Learning O(1) per operation · O(n)
A security vault stacks sealed boxes, and the control panel must flash the smallest serial number currently inside at any moment — without scanning the pile. Each panel action either drops a box, lifts the top box, reads the top serial, or flashes the minimum serial across the whole pile. Design the panel so every action answers instantly.
Input: A list of operations over one stack: ["push", value], ["pop"], ["top"], or ["getMin"].
Output: Return the list of values produced by every top and getMin operation, in order (push and pop produce no output).
1 <= number of operations <= 3 * 10^4-2^31 <= values <= 2^31 - 1pop, top and getMin are always called on a non-empty stackEach operation must run in O(1)Input: {"operations":[["push",-2],["push",0],["push",-3],["getMin"],["pop"],["top"],["getMin"]]}
Output: [-3,0,-2]
The pile bottoms out at -3; after lifting it, the top is 0 and the minimum rises to -2.
Input: {"operations":[["push",1],["push",2],["top"],["getMin"],["pop"],["getMin"]]}
Output: [2,1,1]
Two pushes; the minimum never changes because 1 stays below 2 the whole time.