Skip to content

Practice Maximum Number of Fish in a Grid

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

Medium#2658
LeetCode Problem

Maximum Number of Fish in a Grid

Problem Statement

grid cells with 0 are land; positive values are water cells containing that many fish. Start at any water cell and move only between horizontally or vertically adjacent water cells, collecting each cell's fish at most once. Return the greatest total fish collectible, or 0 if there are no water cells.

Source: Maximum Number of Fish in a Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]
Output
7

# Example 2

Input
grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]
Output
1

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 10
0 <= grid[i][j] <= 10

Related LeetCode Problems

Practice more problems similar to Maximum Number of Fish in a Grid.

Review your practice with PhantomCodeAI

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