Minimum Path Sum
Medium Acceptance 50.00% Points 30.00
Given a n x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Examples
Example 1
Example 1
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: Because the path 1 -> 3 -> 1 -> 1 -> 1 minimizes the sum.
Example 2
Example 2
Input: grid = [[1,2],[4,5]]
Output: 8
Explanation: Because the path 1 -> 2 -> 5 minimizes the sum.
Hints
Hint 1
Expected Time Complexity: O(n^2)
Hint 2
Expected Auxiliary Space: O(n^2)
Constraints
- n == grid.length, grid[i].length
- 1 <= n <= 200
- 0 <= grid[i][j] <= 200
Companies
Amazon Microsoft Samsung Goldman Sachs
Topics
Array Dynamic Programming 2D Array
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.