Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Min Cost Climbing Stairs
Bookmark
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
?
?
dp[i] = min(dp[i-1] + cost[i-1], dp[i-2] + cost[i-2])
0
1
2
3
4
5
6
7
8
9
top
1
?
100
?
1
?
1
?
1
?
100
?
1
?
1
?
100
?
1
?
?
dp[i] = min(dp[i-1] + cost[i-1], dp[i-2] + cost[i-2])
0
1
2
3
4
5
6
7
8
9
top
1
0
100
0
1
?
1
?
1
?
100
?
1
?
1
?
100
?
1
?
?
dp[1]
=
0
free starting spot
0
1
2
3
4
5
6
7
8
9
top
+1
+100
1
0
100
0
1
1
1
?
1
?
100
?
1
?
1
?
100
?
1
?
?
i
dp[3]
= min(
1 + 1
,
0 + 100
) = min(
2
,
100
) =
?
0
1
2
3
4
5
6
7
8
9
top
+1
+1
1
0
100
0
1
1
1
2
1
?
100
?
1
?
1
?
100
?
1
?
?
i
dp[4]
= min(
2 + 1
,
1 + 1
) = min(
3
,
2
) =
?
0
1
2
3
4
5
6
7
8
9
top
+1
+1
1
0
100
0
1
1
1
2
1
2
100
?
1
?
1
?
100
?
1
?
?
i
dp[5]
= min(
2 + 1
,
2 + 1
) = min(
3
,
3
) =
?
0
1
2
3
4
5
6
7
8
9
top
+100
+1
1
0
100
0
1
1
1
2
1
2
100
3
1
3
1
?
100
?
1
?
?
i
dp[6]
= min(
3 + 100
,
2 + 1
) = min(
103
,
3
) =
3
0
1
2
3
4
5
6
7
8
9
top
+1
+100
1
0
100
0
1
1
1
2
1
2
100
3
1
3
1
4
100
?
1
?
?
i
dp[7]
= min(
3 + 1
,
3 + 100
) = min(
4
,
103
) =
4
0
1
2
3
4
5
6
7
8
9
top
+1
+1
1
0
100
0
1
1
1
2
1
2
100
3
1
3
1
4
100
4
1
?
?
i
dp[8]
= min(
4 + 1
,
3 + 1
) = min(
5
,
4
) =
4
0
1
2
3
4
5
6
7
8
9
top
+1
+100
1
0
100
0
1
1
1
2
1
2
100
3
1
3
1
4
100
4
1
5
?
i
dp[10]
= min(
5 + 1
,
4 + 100
) = min(
6
,
104
) =
?
0
1
2
3
4
5
6
7
8
9
top
+1
+1
+1
+1
+1
+1
1
0
100
0
1
1
1
2
1
2
100
3
1
3
1
4
100
4
1
5
6
Min cost to reach the top =
6
algo
master
.
io
Step:
Start: find the minimum cost to reach the top of 10 stairs
0 / 21
Input
Example 1
Example 2
Zeros
Increasing
Two steps
Custom
cost
=
[1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
0 / 21
algo
master
.
io
Step:
Start: find the minimum cost to reach the top of 10 stairs