Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Min Cost Climbing Stairs
Bookmark
Recursion
Memoization
Iterative
Input
Example 1
Example 2
Zeros
Increasing
Two steps
Custom
cost
=
[1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
?
1
?
1
?
100
?
1
?
1
?
100
?
1
?
?
minCost(i) = cost[i] + min(minCost(i+1), minCost(i+2))
calls: 0
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
?
1
?
1
?
100
?
1
?
1
?
100
?
1
?
?
minCost(i) = cost[i] + min(minCost(i+1), minCost(i+2))
calls: 0
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
?
1
?
1
?
100
102
1
3
1
2
100
100
1
1
0
i
calls: 33
0
1
2
3
4
5
6
7
8
9
top
+1
1
?
100
?
1
?
1
?
1
4
100
102
1
3
1
2
100
100
1
1
0
i
minCost(9)
=
1
+ min(
0
,
?
) =
?
calls: 64
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
?
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
calls: 96
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
calls: 127
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
calls: 158
0
1
2
3
4
5
6
7
8
9
top
1
?
100
105
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
minCost(top)
=
0
nothing left to pay
calls: 189
0
1
2
3
4
5
6
7
8
9
top
+1
1
?
100
105
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
minCost(9)
=
1
+ min(
0
,
0
) =
1
calls: 220
0
1
2
3
4
5
6
7
8
9
top
+1
+2
1
?
100
105
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
i
minCost(8)
=
100
+ min(
1
,
0
) =
?
calls: 251
0
1
2
3
4
5
6
7
8
9
top
+1
+1
+1
+1
+1
+1
1
6
100
105
1
5
1
5
1
4
100
102
1
3
1
2
100
100
1
1
0
calls: 464
Min cost to reach the top =
6
algo
master
.
io
Step:
Start: find the minimum cost to reach the top of 10 stairs
0 / 702
Input
Example 1
Example 2
Zeros
Increasing
Two steps
Custom
cost
=
[1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
0 / 702
algo
master
.
io
Step:
Start: find the minimum cost to reach the top of 10 stairs