**Java**  BFS Code || With Explanation
* Please upvote if it is helpful *\n\n# Explanation\n- Given that we have to choose optimal cell i.e grid[r][c] > 0 { water cell } in order to find the maximum 
# ********** Please upvote if it is helpful **********\n\n# Explanation\n- Given that we have to choose optimal cell i.e grid[r][c] > 0 { water cell } in order to find the maximum fishes we can get.\n- Traverse the given grid and apply **BFS** on grid[r][c] > 0\n- We have to calculate the maximum fishes using bfs function.\n- # BFS function explanation\n- First of all add the cell into a queue and mark the cell as visited.\n- Since you are on the cell which have water that consists of fishes so add grid[r][c] to your collection of fishes.\n- Now check all adjacent sides of current cell whose value should not be \'0\' i.e it should be a water cell since if grid[r][c] = 0 it is land and you cant caught fish from land. \n- If it is water cell then it consists of fishes so, add grid[r][c] it to your collection of fishes.\n- Now add the adjacent cell to queue if not visited yet.\n- Lastly **BFS** function returns the number of fishes that you are collected from present cell.\n-  And each time the max fishes that are collected from each cell{grid[r][c] > 0} calculated in main function.\n\n# Complexity\n- Time complexity: O(N + M) \n- Space Complexity : O(N)\n\n# Code\n```\nclass Solution {\n     int[] x = {-1,0,1,0};\n     int[] y = {0,1,0,-1};\n     class Pair {\n        int first;\n        int second;\n        public Pair(int first,int second) {\n            this.first = first;\n            this.second = second;\n        }\n    }\n   \n   \n   \n    public int bfs(int i,int j,boolean[][] vis,int[][] grid) {\n       \n        int sum = 0;\n        Queue<Pair> q = new LinkedList<>();\n        q.add(new Pair(i,j));\n        vis[i][j] = true;\n        sum += grid[i][j];\n        while(!q.isEmpty()) {\n            Pair p = q.poll();\n            int first = p.first;\n            int second = p.second;\n            \n           \n            \n            for(int k = 0;k<4;k++) {\n                \n                int ind1 = x[k] + first;\n                int ind2 = y[k] + second;\n              \n                if(ind1 >=0 && ind2 >=0 && ind1 < grid.length && ind2 < grid[0].length && !vis[ind1][ind2] ){\n                    \n                    \n                     if(grid[ind1][ind2] > 0) {\n                       \n                          sum += grid[ind1][ind2];\n                          q.add(new Pair(ind1,ind2));\n                          vis[ind1][ind2] = true;\n                     }\n                   \n                     \n                }\n                \n            }\n           \n        }\n        return sum;\n    }\n\n     public int findMaxFish(int[][] grid) {\n      int ans= 0;\n        boolean[][] vis = new boolean[grid.length][grid[0].length];\n        \n        for(int i = 0;i<grid.length;i++) {\n            for(int j = 0;j<grid[i].length;j++) {\n                if(!vis[i][j] && grid[i][j] != 0) {\n                    ans = Math.max(ans,bfs(i,j,vis,grid));\n                    \n                }\n            }\n        }\n       \n        return ans;\n    }\n}\n```
['Stack', 'Java']