Problem · Matrix

Maximum Gold Path

Learn this problem
EasyGOGoToNEW GRADOA

Problem 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[][]) → int

Examples

Example 1

grid = [[1,3,3],[2,1,4],[0,6,4]]return = 12

One optimal path is 2 -> 6 -> 4, collecting total gold 12.

Constraints

  • 1 <= grid.length
  • 1 <= grid[i].length
drafts saved locally
public int maxGoldPath(int[][] grid) {
  // write your code here
}
grid[[1,3,3],[2,1,4],[0,6,4]]
expected12
checking account