Minimum Path Sum

Advanced

Minimum Path Sum

Hey young coder! Imagine you have a magical grid filled with numbers where each number represents magic power. You have a task to find the path from the top-left corner to the bottom-right corner such that the total magic power (sum) of the numbers on that path is minimized!

But here’s the rule: You can only move either down or right at any point in time.

Your challenge is to write a function called min_path_sum that takes a grid (a list of lists with integers) as input and returns the minimum sum path from the top-left to the bottom-right corner.

For example, if you have the following grid:

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

The minimum path sum would be 7, since the path 1 → 3 → 1 → 1 → 1 has the sum 7.

Examples

min_path_sum([ [1, 3, 1], [1, 5, 1], [4, 2, 1] ]) # should return 7 min_path_sum([ [1, 2, 5], [3, 2, 1] ]) # should return 6

Have fun and good luck!

Geek
Inputs

Arg 1:

[[1,3,1],[1,5,1],[4,2,1]]
Expected Output
7
Actual Output
Minimum Path Sum [advanced] | Coding for Kids