Best O(M*N) Solution
Approach\nBFS Traversal\n\n# Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn) \n\n# Code\n\nclass Solution {\npublic:\n    int traversal(int 
# Approach\nBFS Traversal\n\n# Complexity\n- Time complexity:\n$$O(m*n)$$\n\n- Space complexity:\n$$O(m*n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int traversal(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& vis) {\n        int m = grid.size(), n = grid[0].size();\n        int fish = 0;\n        queue <pair<int, int>> q;\n        q.push({i, j});\n        vis[i][j] = 1;\n        int drow[] = {-1, 0, 1, 0};\n        int dcol[] = {0, 1, 0, -1};\n        while (!q.empty()) {\n            int r = q.front().first;\n            int c = q.front().second;\n            q.pop();\n            fish += grid[r][c];\n            for (int i = 0; i < 4; i++) {\n                int nr = r + drow[i];\n                int nc = c + dcol[i];\n                if (nr >= 0 && nr < m && nc >= 0 && nc < n\n                    && grid[nr][nc] > 0 && !vis[nr][nc]) {\n                       q.push({nr, nc});\n                       vis[nr][nc] = 1;\n                   }\n            }\n        }\n        return fish;\n    }\n\n    int findMaxFish(vector<vector<int>>& grid) {\n        int m = grid.size(), n = grid[0].size();\n        vector<vector<int>> vis(m, vector<int>(n, 0));\n        int maxFish = 0;\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                if (grid[i][j] > 0 && !vis[i][j]) {\n                    int fish = traversal(i, j, grid, vis);\n                    maxFish = max (maxFish, fish);\n                }\n            }\n        }\n        return maxFish;\n    }\n};\n```
['C++']