FastPrepMin Stack

Min Stack

Microsoft logoMicrosoft● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Process a sequence of operations on a stack that can report its current minimum. The stack starts empty.

  • push x pushes a signed integer and produces no output.
  • pop removes and returns the top integer.
  • top returns the top integer without removing it.
  • getMin returns 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, or getMin.
  • x is a signed 32-bit integer.
  • Every pop, top, and getMin is issued when the stack is nonempty.

More Microsoft problems

See Microsoft hiring insights
public int[] processMinStack(String[] operations) {
    // Write your code here.
}
operations["push -2","push 0","push -3","getMin","pop","top","getMin"]
expected[-3,-3,0,-2]
Checking account…