InferenceAI

Enter at least two characters to search.

Start free

Minimum Path Sum

mediumDynamic Programming25 min25 XP

Return the minimum sum of values along a path from the top-left to the bottom-right of grid, moving only right or down.

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[[[1,3,1],[1,5,1],[4,2,1]]]
TASKmin_path_sum_grid()
EXPECTED OUTPUT7

Start with the input values shown in this example.

Example 1 of 3

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

Output: 7

Explanation: classic

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

Output: 12

Explanation: two rows

Input: grid = [[7]]

Output: 7

Explanation: single cell

Hint 1

best[r][c] = grid[r][c] + min(best above, best to the left).

Topics

DSADynamic ProgrammingPython