Back to problems Solve on LeetCode → See #62 Unique Paths →

Minimum Path Sum

LeetCode 64 • Medium • Dynamic Programming

Given an m×n grid of non-negative weights, find the minimum sum along any path from the top-left to the bottom-right moving only right or down. Example grid: [[1,3,1],[1,5,1],[4,2,1]]7.

TimeO(m×n)fill table
SpaceO(m×n)DP table
Current: Result:
Grid weight
Min sum so far
Current cell
dp[i][j]
Ready
Press Play. dp[i][j] = minimum path sum to (i,j). First cell = grid[0][0]; edge cells = sum along edge; interior = grid[i][j] + min(up, left).