Problem
Design a stack that can also return its smallest item. A stack is a list where you add and remove items only at the top.
Write the class MinStack with these operations:
MinStack() creates an empty stack. push(val) adds the integer val at the top. pop() removes the item at the top. top() returns the item at the top. getMin() returns the smallest item in the stack.
Each operation must run in O(1) time. The tests call pop, top and getMin only when the stack is not empty.
Example 1
- Input:
- ["MinStack","push","push","push","getMin","pop","getMin","top"] [[],[5],[2],[8],[],[],[],[]]
- Output:
- [null,null,null,null,2,null,2,2]
- Explanation:
- After the three pushes, the smallest item is 2. The
popremoves 8, so the smallest item is still 2.
Example 2
- Input:
- ["MinStack","push","push","getMin","pop","getMin"] [[],[3],[-1],[],[],[]]
- Output:
- [null,null,null,-1,null,3]
- Explanation:
- The
popremoves -1. Then 3 is the smallest item again.
Constraints
- -2^31 <= val <= 2^31 - 1
- pop, top and getMin are called only on a non-empty stack.
- At most 3 * 10^4 calls to push, pop, top and getMin
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Max Stack
Coding · Design · Doubly-Linked List · Linked List
- Design Browser History
Coding · Array · Data Stream · Design
- Flatten Nested List Iterator
Coding · Depth-First Search · Design · Iterator
- 132 Pattern
Coding · Array · Binary Search · Monotonic Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Expedia
Leetcode 155. Min Stack
Reported Jun 4, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceSnowflake
Leetcode 155. Min Stack
Reported Jun 27, 2026 · 3 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 1 record
Snowflake
Min Stack
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 62.9. This is not an interview probability.
View source