You are given an m x n grid filled with non-negative numbers. Starting from the top-left cell you want to reach the bottom-right cell, and on each move you may travel only one cell to the right or one cell down.
Return the smallest possible sum of all numbers along a valid path from the top-left corner to the bottom-right corner.
Example 1
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
The route 1 -> 3 -> 1 -> 1 -> 1 accumulates the minimum total of 7.
Example 2
Input: grid = [[1,2,3],[4,5,6]]
Output: 12
The path 1 -> 2 -> 3 -> 6 sums to 12, the least achievable for this grid.
Constraints
m == grid.lengthn == grid[i].length1 <= m, n <= 2000 <= grid[i][j] <= 200See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI