✅✅DFS Approach || Easy to understand || Standard method || C++ || beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nThis is a standard traversal problem where we will traverse each component, find the su
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a standard traversal problem where we will traverse each component, find the sum of fishes on each component and find out the maximum of all the sums.\n\n# Complexity\n- Time complexity: O(M*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    using vvi = vector<vector<int>>;\n    void dfs(vvi& grid, int i,int j, int& sum){\n        int m = grid.size();\n        int n = grid[0].size();\n        if(i>=m || i<0 || j<0 || j>=n){\n            return;\n        }\n        if(grid[i][j]!=0 && grid[i][j]!=-1){\n            sum += grid[i][j];\n            grid[i][j]=-1;\n            dfs(grid,i+1,j,sum);\n            dfs(grid,i,j+1,sum);\n            dfs(grid,i-1,j,sum);\n            dfs(grid,i,j-1,sum);\n        }\n    }\n    int findMaxFish(vector<vector<int>>& grid) {\n        int m = grid.size();\n        int n = grid[0].size();\n        int ans = INT_MIN;\n        int sum=0;\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]>0){\n                    dfs(grid,i,j,sum);\n                    ans = max(ans,sum);\n                    sum=0;\n                }\n            }\n        }\n    \n        return ans==INT_MIN?0:ans;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C++']