Problem
A gold mine is a grid where grid[r][c] is the amount of gold in that cell (0 means empty). You collect gold by walking a path: start at any cell with gold, and each step moves up, down, left or right to another cell with gold. You may never visit a cell twice and never step onto an empty cell. Return the maximum gold you can collect.
Example 1
[[0, 6, 0],
Example 2
[5, 8, 7],
Example 3
- Input
- [0, 9, 0]]
- Output
- 24
- Why
- 9 → 8 → 7
Example 4
[[1, 0, 7],
Example 5
[2, 0, 6],
Example 6
[3, 4, 5],
Example 7
[0, 3, 0],
Example 8
- Input
- [9, 0, 20]]
- Output
- 28
- Why
- 1 → 2 → 3 → 4 → 5 → 6 → 7
Constraints
1 <= rows, cols <= 150 <= grid[r][c] <= 100At most 25 cells contain gold.