FrontendX
Minimum Path Sum
medium
Blind solve
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Minimum Path
Sum
Return the minimum sum path from top-left to bottom-right, moving only right or down at each step.
Examples
Example 1
Input:
[[1,3,1],[1,5,1],[4,2,1]]
Output:
7
Example 2
Input:
[[1,2,3],[4,5,6]]
Output:
12
Hints
Hint 1
Use dynamic programming to build a 2D table where `dp[i][j]` represents the minimum path sum to reach cell `(i, j)` from `(0, 0)`.
Hint 2
For each cell `(i, j)`, compute `dp[i][j]` as `grid[i][j] + min(dp[i-1][j], dp[i][j-1])`, handling boundary conditions (first row/column) separately.
Hint 3
Optimize space by using a 1D array (rolling array) to store only the current and previous row, reducing space complexity from O(mn) to O(n).
Related Problems
triangle
unique-paths
unique-paths-ii
1
/**
2
* @param {number[][]} arg1
3
* @return {number}
4
*/
5
function solve(arg1) {
6
// solve Minimum Path Sum problem here
7
return 0;
8
}
Click to start editing · javascript
Minimum Path Sum
Return the minimum sum path from top-left to bottom-right, moving only right or down at each step.