Profile picture
Alvin ZablanFounder at Structy and React Formula | ex-Google

Max Path Sum Approach

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function, max_path_sum, that takes in a grid as an argument. The function should return the maximum sum possible by traveling a path from the top-left corner to the bottom-right corner. You may only travel through the grid by moving down or right.

You can assume that all numbers are non-negative.

grid = [
[1, 3, 12],
[5, 1, 1],
[3, 6, 1],
]

max_path_sum(grid) # -> 18
grid = [
[1, 2, 8,  1],
[3, 1, 12, 10],
[4, 0, 6,  3],
]

max_path_sum(grid) # -> 36
grid = [
[1, 2, 8, 1],
[3, 10, 12, 10],
[4, 0, 6, 3],
]

max_path_sum(grid) # -> 39

If you need additional support taking these DSA skills and actually applying them, take Alvin's complete data structures and algorithms course on Structy. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use this link to get 20% off the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: https://www.linkedin.com/in/alvin-zablan-b73a92117/