Skip to content

Practice Path with Maximum Gold

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1219
LeetCode Problem

Path with Maximum Gold

Problem Statement

Each cell of grid contains its available amount of gold, with 0 indicating an empty cell. Start at any cell containing gold, move only up, down, left, or right, and stop wherever you choose. Collect all gold from every visited cell, never visit a zero-valued cell, and never visit the same cell twice. Return the maximum gold obtainable along one such path.

Source: Path with Maximum Gold on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[0,6,0],[5,8,7],[0,9,0]]
Output
24

# Example 2

Input
grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
Output
28

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.

Related LeetCode Problems

Practice more problems similar to Path with Maximum Gold.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.