82. Minimum Path Sum

Moving only right or down from the top-left to the bottom-right of grid, minimise the sum of the numbers on your path.

Example 1

Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: Path 1 → 3 → 1 → 1 → 1.

Example 2

Input: grid = [[1,2,3],[4,5,6]]
Output: 12
Hint 1

best(r, c) = grid[r][c] + min(best(r−1, c), best(r, c−1)).

Dynamic ProgrammingMatrix