Min Stack
Problem statement
Process a sequence of operations on a stack that can report its current minimum. The stack starts empty.
push xpushes a signed integer and produces no output.popremoves and returns the top integer.topreturns the top integer without removing it.getMinreturns the smallest integer currently in the stack.
Return one integer result for each pop, top, or getMin operation in encounter order. Support every operation in constant time. The reported interview included unspecified follow-ups; this judged contract covers the standard Min Stack baseline.
Function
processMinStack(operations: String[]) → int[]Examples
Example 1
operations = ["push -2","push 0","push -3","getMin","pop","top","getMin"]return = [-3,-3,0,-2]The minimum changes after pushing -3. Popping returns -3, then the minimum returns to -2.
Example 2
operations = ["push 2","push 2","getMin","pop","getMin"]return = [2,2,2]Duplicate minima are tracked independently; one pop still leaves minimum 2.
Example 3
operations = ["push 2147483647","push -2147483648","getMin","pop","getMin"]return = [-2147483648,-2147483648,2147483647]Minimum tracking works across the full signed 32-bit value range.
Constraints
1 <= operations.length <= 100000.- Each operation is one of
push x,pop,top, orgetMin. xis a signed 32-bit integer.- Every
pop,top, andgetMinis issued when the stack is nonempty.