Dynamic programmingAnimated
Minimum Path Sum
Cheapest grid path moving right or down.
Time
O(m · n)
Extra space
O(n)
Use it for
Route cost minimisation.
How it works
- Each cell has a cost. Move only right or down from top-left to bottom-right, minimising the total cost.
- best(cell) = cost(cell) + min(best(above), best(left)).
- The first row and column only have one way in.
- The bottom-right value is the cheapest route. O(rows × columns).
Watch it run
Loading animation…