Path with Maximum Gold

In a gold mine grid of size m x n, each cell has an integer representing the amount of gold or 0 if empty. The task is to return the maximum amount of gold you can collect with these conditions: collect gold from the current cell, move one step up, down, left, or right, don't revisit a cell, don't visit cells with 0 gold, start and stop at any position with gold.

Constraints

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 15
  • 0 <= grid[i][j] <= 100
  • There are at most 25 cells containing gold.
Saving… · 3 lines
class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:

Console

Click Run to execute sample tests.