Skip to content

2658. Maximum Number of Fish in a Grid #1236

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The problem is to find the maximum number of fish that a fisher can catch by starting at any water cell in a grid. The fisher can catch fish at the current cell and move to any adjacent water cell (up, down, left, or right) repeatedly.

Key Points:

  1. The grid contains cells that are either land (value 0) or water (value > 0).
  2. The fisher can only move to adjacent water cells.
  3. The objective is to find the maximum number of fish collectable, starting from the best possible water cell.

Approach:

  1. Use Depth-First Search (DFS) to explore all possible paths starting from each water cell.
  2. For each unvisited water cell, run a DFS to calculate the total fish in the connected component.
  3. Track the max…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jan 28, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jan 28, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants