dsa · medium

Minimum Path Sum

grid is an m × n map of non-negative integers. Start at the top-left and move only right or down to the bottom-right. Return the smallest sum of the cells you visit, including start and end.

Arguments

Example

[[1,3,1],[1,5,1],[4,2,1]]7 along 1 → 3 → 1 → 1 → 1.

Constraints

1 <= m, n <= 200 0 <= grid[i][j] <= 200 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[[1,3,1],[1,5,1],[4,2,1]]

Expected:
7

Example 2

Input:
[[1,2,3],[4,5,6]]

Expected:
12

Open in the Dojo editor