Min Stack
Updated
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. This is the standard Min Stack.
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.
More Microsoft Phone Screen questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
- Min StackDP World · ONSITE INTERVIEW
- Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
- Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
- In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
- Undo and Redo Command HistoryNetflix · ONSITE INTERVIEWNetflix interview questions
- Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions