DFS JAVA AC CONCISE SOLUTION
My idea is similar to the problem: number of islands\n\n\nclass Solution {\n    public int largestIsland(int[][] grid) {\n        int max = 0, m = grid.length, 
My idea is similar to the problem: number of islands\n\n```\nclass Solution {\n    public int largestIsland(int[][] grid) {\n        int max = 0, m = grid.length, n = grid[0].length;\n        boolean hasZero = false; //To check if there is any zero in the grid\n        for(int i = 0; i < grid.length; i++){\n            for(int j = 0;j<grid[0].length;j++){\n                if(grid[i][j] == 0){\n                    grid[i][j] = 1;\n                    max = Math.max(max,dfs(i,j,grid,new boolean[m][n]));   \n                    if(max == m*n) return max;\n                    grid[i][j] = 0;\n                    hasZero = true;\n                }\n            }\n        }\n        return hasZero?max:m*n;\n    }\n    private int dfs(int i, int j, int[][] grid,boolean[][] visited){\n        if(i < 0 || j < 0 || i >= grid.length || j >= grid[0].length || grid[i][j] == 0||visited[i][j]) return 0;\n        visited[i][j] = true;\n        int result = 1+dfs(i-1,j,grid,visited)+dfs(i+1,j,grid,visited)+dfs(i,j+1,grid,visited)+dfs(i,j-1,grid,visited);\n        return result;\n    }\n}\n```
[]