✅ C++ BFS Solution ✅
Intuition\n Describe your first thoughts on how to solve this problem. \n- BFS traversal on the Connected Components. Just a variation of LC #200[Number Of Isla
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- BFS traversal on the Connected Components. Just a variation of LC #200[Number Of Islands]\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- The code uses a breadth-first search (BFS) approach to traverse the water cells in the given grid and calculate the maximum number of fish that can be caught.\n\n- For each water cell in the grid, the BFS is applied to find out  all the connected water cells and count the total number of fish in those cells.\n\n- The maximum fish count obtained from all the BFS traversals is then returned as the result.\n\n# Complexity\nTime complexity:  O(m * n(m + n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- where m and n are the number of rows and columns in the input grid. In the worst case, we may have to traverse all the water cells in the grid, and each BFS traversal takes O(m + n) time.\n\nSpace complexity: O(m * n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n- since we are using a 2D visited matrix to keep track of the visited water cells. In the worst case, all the water cells may need to be visited, requiring a visited matrix of size mn. Additionally, the queue used in BFS will hold a maximum of O(m*n) water cell positions at any point in time.\n\n# Code\n```\nclass Solution {\npublic:\n\n    int maxFishes = INT_MIN;\n\n    void bfs(int row, int col, vector <vector<int>> &grid, vector <vector<int>> &vis, int dx[], int dy[])\n    {\n        int n = grid.size();\n        int m = grid[0].size();\n        \n        vis[row][col] = 1;\n        queue <pair<int, int>> q;\n        q.push({row, col});\n\n        int fishes = 0;\n        while(!q.empty())\n        {\n            int x = q.front().first;\n            int y = q.front().second;\n\n            //adding the count of the number of fishes in the current cell\n            fishes += grid[x][y];\n            q.pop();\n\n            //finding out the current cell neighbours\n            for(int i = 0; i < 4; i++)\n            {\n                int nRow = x + dx[i];\n                int nCol = y + dy[i];\n                \n                //check for the validity of neighbouring row & col\n                if(nRow >= 0 && nRow < n && nCol >= 0 && nCol < m && grid[nRow][nCol] > 0 && !vis[nRow][nCol])\n                {\n                    vis[nRow][nCol] = 1;\n                    q.push({nRow, nCol});\n                }\n            }\n        }\n\n        maxFishes = max(maxFishes, fishes);\n        return;\n    }\n    \n    int findMaxFish(vector<vector<int>>& grid) \n    {\n        //no of rows\n        int n = grid.size();\n        \n        //no of cols\n        int m = grid[0].size();\n        \n        //create the visited matrix to keep track of the water cell\n        vector <vector <int>> vis(n, vector <int> (m, 0));\n        \n        //can move only in 4-directions\n        int dx[] = {0, 0, 1, -1};\n        int dy[] = {1, -1, 0, 0};    \n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = 0; j < m; j++)\n            {\n                if(grid[i][j] > 0 && !vis[i][j])\n                    bfs(i, j, grid, vis, dx, dy);\n            }\n        }\n        \n        return maxFishes == INT_MIN ? 0 : maxFishes;\n    }\n};\n```
['C++']