Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Min Stack
Bookmark
Brute Force
Two Stacks
Single Stack Pairs
Input
LeetCode Example
Mixed Ops
Push & Top
Custom
operations
=
[push -2, push 0, push -3, getMin, pop, top, getMin]
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
stack
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
stack
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
-3
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
-3
getMin scans the whole stack
(O(n))
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
-3
min
-3
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
-3
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
top
0
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
i
stack
-2
0
getMin scans the whole stack
(O(n))
operations
push -2
push 0
push -3
getMin
pop
top
getMin
0
1
2
3
4
5
6
stack
-2
0
algo
master
.
io
Step:
MinStack (brute force): store values only, scan for the min
0 / 21
Input
LeetCode Example
Mixed Ops
Push & Top
Custom
operations
=
[push -2, push 0, push -3, getMin, pop, top, getMin]
0 / 21
algo
master
.
io
Step:
MinStack (brute force): store values only, scan for the min