Find the minimum sum path from the top-left to the bottom-right of a grid by moving only right or down.
You are given a 2D grid of non-negative integers. Start at the top-left cell and move to the bottom-right cell. At each step, you may move only right or only down.
Return the minimum possible sum of the values along any valid path, including both the starting and ending cells.
A good solution should avoid exploring all paths directly and instead reuse partial answers from smaller subproblems.
grid with m rows and n columns.grid[i][j] is the cost of entering cell (i, j).grid[0][0] to grid[m-1][n-1].1 <= m, nExample 1
Input
grid = [[1,3,1],[1,5,1],[4,2,1]]
Output
7
Explanation
One optimal path is 1 → 3 → 1 → 1 → 1, which sums to 7.
Example 2
Input
grid = [[1,2,3],[4,5,6]]
Output
12
Explanation
The minimum path is 1 → 2 → 3 → 6, with total sum 12.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.