Problem · Matrix
Maximum Gold Path
Learn this problemProblem statement
You are given a 2D integer grid grid, where each cell contains some amount of gold.
You may start from any cell in the first column. From a cell (row, col), you may move to one of the following cells in the next column:
(row, col + 1)(row - 1, col + 1)(row + 1, col + 1)
Return the maximum total gold you can collect by following a valid path from the first column to the last column.
Function
maxGoldPath(grid: int[][]) → intExamples
Example 1
grid = [[1,3,3],[2,1,4],[0,6,4]]return = 12One optimal path is 2 -> 6 -> 4, collecting total gold 12.
Constraints
1 <= grid.length1 <= grid[i].length