DFS Solution for 'Maximum Number of Fish in a Grid'  | Intuitive & Clean Code 💡
IntuitionThe problem is like finding the biggest group of fish in a grid. Think of each cell in the grid as a pond. If two ponds (cells) are next to each other
# Intuition
The problem is like finding the biggest group of fish in a grid. Think of each cell in the grid as a pond. If two ponds (cells) are next to each other and have fish, we can treat them as part of the same group. Our goal is to figure out the total number of fish in the biggest group. To do this, we can explore all connected ponds using a technique called DFS (Depth-First Search).

# Approach
- Use DFS to explore connected cells with fish, summing up their values.

- Keep track of visited cells to avoid re-processing.

- For each unvisited cell with fish, calculate the total fish in its connected component and update the maximum.

- Return the largest fish count found.

# Complexity
- Time complexity:
O ( r * c)

- Space complexity:
O ( r * c)

# Code
```python []
class Solution(object):
    def findMaxFish(self, grid):
        def dfs(r,c):
            if( r<0 or c<0 or
                r == rows or c == cols or
                grid[r][c] == 0 or visit[r][c]):

                return 0

            visit[r][c] = True
            res = grid[r][c]
            neigh = [[r+1,c],[r-1,c],[r,c+1],[r,c-1]]
            for nr, nc in neigh:
                res += dfs(nr,nc)
            return res

        rows, cols = len(grid),len(grid[0])
        res = 0
        visit=[[False] * cols for _ in range(rows)]
        for r in range(rows):
            for c in range(cols):
                if grid[r][c] or not visit[r][c]:
                    res =max(res,dfs(r,c))
        return res
        
```
['Depth-First Search', 'Python']