Minimum Path Sum
Given an m x n grid filled with non-negative numbers, find a path from the top-left cell to the bottom-right cell that minimizes the sum of numbers along the path. You may only move either right or down at any step. Return that minimum sum.
Open official problem prompt ↗Compute the smallest possible sum of values collected while walking from the top-left corner to the bottom-right corner, moving only right or down.
Think of a toll-road map where every intersection charges a fee. From home you can only drive east or south to work. The cheapest fare to any intersection is its own toll plus the cheaper of the two roads feeding into it.
- Input
- grid = [[1,3,1],[1,5,1],[4,2,1]]
- Output
- 7
- Why
- The path 1 -> 3 -> 1 -> 1 -> 1 sums to 7, which is smaller than any other right/down path.
m == grid.lengthn == grid[i].length1 <= m, n <= 2000 <= grid[i][j] <= 200