"🚀🚀Maximize Fish Catch🔥🔥|| ✅Efficient Solution by Kanishka✅|| 🔥🔥Beginner Friendly Solution🚀🚀
🧠 IntuitionThe first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The g
# 🧠 Intuition
The first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The goal is to find the maximum fish count in any connected component.

# 🔍 Approach
Here's the approach step-by-step:
1. **Initialize Variables**: Set up a `visited` array to keep track of visited cells and an `answer` variable to store the maximum fish count found.
2. **Traverse the Grid**: For each cell in the grid, if it is not visited and contains a non-zero value, use DFS to explore the connected component.
3. **DFS Exploration**: For each unvisited cell in the connected component, mark it as visited and accumulate the fish count.
4. **Update Maximum**: After exploring each connected component, update the `answer` with the maximum fish count found.

# ⏳ Complexity
- **Time Complexity**: $$O(n \times m)$$
  - We traverse each cell in the grid once.
- **Space Complexity**: $$O(n \times m)$$
  - We use additional space for the `visited` array and recursion stack.

# 📜 Code
```java
class Solution {
    public int max;
    public int findMaxFish(int[][] grid) {
        int rlen = grid.length;
        int clen = grid[0].length;
        int answer = 0;
        boolean visited[][] = new boolean[rlen][clen];
        for(int i=0;i<rlen;i++){
            for(int j=0;j<clen;j++){
                if(grid[i][j]!=0 && !visited[i][j]){
                    max = 0;
                    dfs(grid, rlen, clen, visited, i, j);
                    answer = Math.max(max, answer );
                }
            }
        }
        return answer;
    }
    
    public void dfs(int[][] grid, int rlen, int clen, boolean[][] visited, int i, int j){
        if(i<0 || i>=rlen || j<0 || j>=clen || visited[i][j] || grid[i][j] == 0){
            return;
        }
        visited[i][j] = true;
        max += grid[i][j];
        dfs(grid, rlen, clen, visited, i+1, j);
        dfs(grid, rlen, clen, visited, i-1, j);
        dfs(grid, rlen, clen, visited, i, j+1);
        dfs(grid, rlen, clen, visited, i, j-1);
    }
}

['Depth-First Search', 'Java']