DFS || Java || Easy Solution || Beat 100% || 
To do this, we can use Depth-First Search (DFS), to explores all connected parts of a region recursivelyApproach

Walk Through the Grid:

Look at each cell in t
**To do this, we can use Depth-First Search (DFS), to explores all connected parts of a region recursively**

---

# Approach
1. **Walk Through the Grid**:  
   - Look at each cell in the grid. If the cell contains fish (not zero)...Start a **DFS search** from that cell to find all the fish from neighbor cell 

2. **Explore the Pond Using DFS**:  
   - When DFS starts at a cell, it will look at the four neighboring cells (up, down, left, right) 
   - If a neighbor also contains (Non zero number)fish, the DFS will move to that neighbor and continue exploring
   - Each time DFS visits a cell, it adds the number to the total count (`res`) and marks the cell as visited by setting it to `0`(`grid[r][c]=0`;) (to avoid counting it again)

3. **Keep Track of the Maximum count**:  
   - After the DFS finishes exploring a grid, compare its count with the current maximum. If it's larger, update the maximum
   (It is done inside For loop,once dfs method return counnt)


4. **Repeat for All Cells**:  
   - Continue this process for all cells(which is not zero) in the grid until you've checked every part

---


# Code

```java
class Solution {
    public int findMaxFish(int[][] grid) {
        int max=0;
        for(int r=0;r<grid.length;r++){
            for(int c=0;c<grid[0].length;c++){
                if(grid[r][c]!=0){
                   
                    max=Math.max(dfs(r,c,grid),max);
                     // System.out.println(max);
                }
                
            }

        }
        return max;
        
    }
    public static int dfs(int r,int c,int[][] grid){
        if(r<0 || c<0 || r>grid.length-1 || c>grid[0].length-1 || grid[r][c]==0){
            return 0;
        }
        int res=grid[r][c];
        grid[r][c]=0;
        
        res+=dfs(r,c+1,grid)+dfs(r,c-1,grid)+dfs(r+1,c,grid)+dfs(r-1,c,grid);
        
        // System.out.println(res);
        
        return res;
    }
}
```



['Java']