FastPrepMin Stack
Problems/Min Stack

Min Stack

Shopify logoShopify● MediumINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for a min-stack with constant-time minimum retrieval. This version matches the reported core at about 85%; the command batch, valid-call rule, examples and bounds are practice assumptions.

Implement a stack with push, pop, top, and getMin. Each operation, including minimum lookup, must take O(1) time.

For this exercise, assume a fresh empty stack receives the ordered commands in operations. A push uses the matching entry in values; other commands ignore that entry. Return an array containing the answers to top and getMin, in command order. push and pop produce no output.

For this exercise, assume pop, top, and getMin are called only when the stack is nonempty.

Function

runMinStack(operations: String[], values: int[]) → int[]

Examples

Example 1

operations = ["push","push","push","getMin","pop","top","getMin"]values = [-2,0,-3,0,0,0,0]return = [-3,0,-2]

After the three pushes, the stack is [-2,0,-3], with minimum -3. Popping removes -3. The remaining top is 0 and minimum is -2.

Example 2

operations = ["push","push","pop","getMin"]values = [4,4,0,0]return = [4]

Both pushes add 4. Removing one copy leaves the other, so the minimum remains 4.

Constraints

  • 0 <= operations.length <= 20000
  • values.length == operations.length
  • Every operation is push, pop, top, or getMin.
  • pop, top, and getMin are called only when the stack is nonempty.
  • -10^9 <= values[i] <= 10^9

More Shopify problems

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Mars Rover Robot ControllerPHONE SCREEN · Seen Oct 2026
  • Choose Items for a BackpackOA · Seen May 2026
All Shopify interview questionsSee Shopify hiring insights
Saved
public int[] runMinStack(String[] operations, int[] values) {
    // Return the results of top and getMin commands.
}
Checking account…