Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Path Sum
Bookmark
Recursion
2D DP
Space Optimized
Input
Example 1
Example 2
Example 3
Example 4
Custom
grid
=
[[1,3,1],[1,5,1],[4,2,1]]
grid =
3x3
start
end
1
3
1
1
5
1
4
2
1
calls: 0
every step costs its cell; find the cheapest right/down route
grid =
3x3
start
end
1
3
1
1
5
1
4
2
1
calls: 0
every step costs its cell; find the cheapest right/down route
grid =
3x3
start
end
1
3
1
1
5
1
4
2
1
calls: 3
row 0
cheaper of top / left, plus the cell cost
grid =
3x3
start
end
1
3
1
1
5
1
4
2
1
calls: 7
grid =
3x3
start
end
1
1
4
3
5
1
1
5
1
4
2
1
calls: 10
grid =
3x3
start
end
1
1
4
3
5
1
1
5
1
4
2
1
calls: 13
dp[0][0]
= grid[0][0] =
1
the route starts here
grid =
3x3
start
end
1
1
4
3
5
1
2
1
7
5
6
1
4
2
1
calls: 16
grid =
3x3
start
end
1
1
4
3
5
1
2
1
7
5
6
1
4
2
1
calls: 19
dp[0][0]
= grid[0][0] =
1
the route starts here
grid =
3x3
start
end
1
1
4
3
5
1
2
1
7
5
6
1
4
2
1
calls: 22
min(
1
,
) +
1
=
+ 1 =
2
grid =
3x3
start
end
1
1
4
3
5
1
2
1
7
5
6
1
4
2
1
calls: 26
grid =
3x3
start
end
1
1
4
3
5
1
2
1
7
5
6
1
6
4
8
2
7
1
calls: 27
min path sum =
7
= 1 + 3 + 1 + 1 + 1
algo
master
.
io
Step:
Every cell has a cost. Find the cheapest top-left to bottom-right route, moving only right or down
0 / 90
Input
Example 1
Example 2
Example 3
Example 4
Custom
grid
=
[[1,3,1],[1,5,1],[4,2,1]]
0 / 90
algo
master
.
io
Step:
Every cell has a cost. Find the cheapest top-left to bottom-right route, moving only right or down