Maximum Number of Fish in a Grid [C++]
Intuition:The approach uses DFS to traverse connected non-zero cells, treating them as a single component (or "pond"). Each DFS call sums the fish count for all
### Intuition:
The approach uses DFS to traverse connected non-zero cells, treating them as a single component (or "pond"). Each DFS call sums the fish count for all connected cells and updates the maximum count found.

### Approach:
1. **DFS Traversal**: Each cell with non-zero fish count acts as a starting point. The DFS explores all connected cells in four directions (up, down, left, right).
2. **Marking Visited Cells**: During traversal, visited cells are set to zero to avoid revisiting and ensure correct component-based counting.
3. **Finding Maximum Fish**: Iterate through all cells in the grid, invoking DFS for each non-zero cell to calculate the total fish in that pond.

### Complexity:
- **Time Complexity**: \(O(n \times m)\), where \(n\) and \(m\) are the dimensions of the grid. Each cell is visited once during the DFS, and the grid is iterated over once.
- **Space Complexity**: \(O(n \times m)\) in the worst case due to the recursion stack in DFS for a fully connected grid.

### Code:
The code is well-structured and handles the problem efficiently:

```cpp
class Solution {
public:
    int dfs(int i, int j, vector<vector<int>>& grid) {
        int n = grid.size(), m = grid[0].size();
        if (i < 0 || j < 0 || i >= n || j >= m || grid[i][j] == 0) 
            return 0;
        int cur = grid[i][j];
        grid[i][j] = 0;  // Mark as visited
        cur += dfs(i + 1, j, grid);
        cur += dfs(i - 1, j, grid);
        cur += dfs(i, j + 1, grid);
        cur += dfs(i, j - 1, grid);
        return cur;
    }

    int findMaxFish(vector<vector<int>>& grid) {
        int n = grid.size(), m = grid[0].size(), ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[i][j] != 0) {
                    ans = max(ans, dfs(i, j, grid));
                }
            }
        }
        return ans;
    }
};
```
['C++']