1137. Minimum Path Sum in Grid

EasyDynamic ProgrammingGrid DP

Given a grid of non-negative numbers, find a path from the top-left to the bottom-right that minimizes the sum of numbers along it, moving only right or down. Return that minimum sum. The input is JSON {grid}.

Input: JSON {grid}.

Output: Integer — the minimum path sum.

Examples

Example 1
Input: {"grid":[[1,3,1],[1,5,1],[4,2,1]]}
Output: 7
Explanation: 1->3->1->1->1 sums to 7.
Example 2
Input: {"grid":[[1,2,3]]}
Output: 6
Explanation: Single row.
Example 3
Input: {"grid":[[5]]}
Output: 5
Explanation: Single cell.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →