Minimum Path Sum
Cheapest top-left → bottom-right path in a grid of non-negative costs, moving only right or down.
Open on LeetCode ↗Intuition
You can only arrive at a cell from above or from the left, so the cheapest way to reach it is its own cost plus the cheaper of those two arrivals. Fill the grid in reading order and every cell's answer is ready when you need it — the bottom-right cell ends up holding the global minimum.
Approach
State and transition
dp[r][c] = min cost to reach (r,c) = grid[r][c] + min(dp[r-1][c], dp[r][c-1]).
Edges are forced
Top row can only come from the left, first column only from above — running prefix sums, no min needed.
In-place fill
Overwrite the grid itself: no extra memory, and the traversal order (row by row) guarantees dependencies are computed first.
Solution & live demo
Edge cases
Answer is grid[0][0] itself.
Forced path — plain sum, handled by the edge initialization.
Always taking the locally cheaper step can miss a cheap corridor later — that's why DP, not greedy.