Quant Memo
Coding/●●●●●

Grid path that may also step diagonally

Collect value walking from the top-left to the bottom-right cell of a grid. At each step you may move right, down, or diagonally down-right.

grid = [[2, 1, 3],
        [1, 9, 1],
        [4, 2, 7]]
-> 21          # path 2 -> 1 -> 9 -> 2 -> 7

Return the maximum total collectible. Aim for O(nm)O(nm).

Show a hint

With three allowed moves, a cell can be entered from the left, from above, or from the upper-left diagonal. The best path into a cell picks the strongest of those three predecessors.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions