My first DFS solution 🚀 || No reference Needed just follow the sol. explanation || 100 % TC || C++
Intuition 💡The problem involves finding the maximum number of fish that can be collected in a connected component of a grid. Each cell with a non-zero value rep

### Intuition 💡
The problem involves finding the maximum number of fish that can be collected in a connected component of a grid. Each cell with a non-zero value represents a pond, and we can "collect fish" by exploring all adjacent cells in the same connected component. This is a classic **grid traversal problem** solvable using **Depth First Search (DFS)**.

---

### Approach 🛠️
1. **Grid Representation**: Treat the grid as a matrix where each cell either has fish (`grid[i][j] > 0`) or is empty (`grid[i][j] == 0`).
2. **DFS Traversal**:
   - Start from an unvisited cell containing fish.
   - Use DFS to traverse the connected component and calculate the total number of fish.
   - Mark the cells as visited during traversal.
3. **Track Maximum Fish**: Keep a running maximum of fish collected for each connected component.

---

### Complexity 📊
- **Time Complexity**:  
  $$O(r \times c)$$  
  Every cell is visited at most once during DFS, where \(r\) and \(c\) are the grid dimensions.
  
- **Space Complexity**:  
  $$O(r \times c)$$  
  Due to the `visited` matrix and the recursion stack in the worst case.

---

### Stylish Code ✨
```cpp
class Solution {
public:
    // Directions for moving up, down, left, and right ➡️⬅️⬇️⬆️
    vector<pair<int, int>> directions{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    
    // Helper function: Perform DFS to calculate the total fish in a connected component
    int dfs(int i, int j, int rows, int cols, vector<vector<int>>& grid, vector<vector<bool>>& visited) {
        // Base conditions: Out of bounds or invalid cell
        if (i < 0 || j < 0 || i >= rows || j >= cols || grid[i][j] == 0 || visited[i][j]) {
            return 0;
        }

        // Mark the current cell as visited and start with the current cell's fish count
        visited[i][j] = true;
        int totalFish = grid[i][j];

        // Explore all four directions recursively
        for (auto dir : directions) {
            totalFish += dfs(i + dir.first, j + dir.second, rows, cols, grid, visited);
        }

        return totalFish;
    }
    
    // Main function to find the maximum fish
    int findMaxFish(vector<vector<int>>& grid) {
        int rows = grid.size();
        int cols = grid[0].size();
        
        // Visited matrix to keep track of explored cells
        vector<vector<bool>> visited(rows, vector<bool>(cols, false));
        
        int maxFish = 0; // Variable to track the maximum fish in a connected component
        
        // Iterate through each cell in the grid
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                // If the cell contains fish and hasn't been visited, perform DFS
                if (grid[i][j] > 0 && !visited[i][j]) {
                    maxFish = max(maxFish, dfs(i, j, rows, cols, grid, visited));
                }
            }
        }
        
        return maxFish; // Return the maximum fish collected
    }
};
```

---

### Explanation 🔍
1. **Directions Array**: Encodes the 4 possible moves (right, left, down, up).
2. **DFS Function**: 
   - Checks for valid cells (within bounds, not visited, and contains fish).
   - Recursively explores all connected cells to accumulate the total fish.
3. **Main Function**:
   - Iterates over the grid and starts a DFS traversal for each unvisited cell with fish.
   - Updates the maximum fish collected after each DFS traversal.

---

### Why Upvote This Solution? 🙌
- **Clarity**: Well-structured and easy-to-read code with intuitive variable names.
- **Efficiency**: Optimized traversal logic with minimal overhead.
- **Scalability**: Handles grids of any size while ensuring correctness.
- **Style**: Clean and modular with comments and emojis for better understanding. 😎

If this solution helped you, **please upvote**! 👍✨
['Array', 'Depth-First Search', 'Graph', 'Matrix', 'C++']