Java simple and easy to understand solution, clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\nclass Solution {\n    static int[][] DIRECTIONS = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n    private int r
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n```\nclass Solution {\n    static int[][] DIRECTIONS = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n    private int rows;\n    private int cols;\n    \n    public int largestIsland(int[][] grid) {\n        rows = grid.length;\n        cols = grid[0].length;\n        \n        \n        int[] areas = new int[rows * cols + 2];\n        int areaIndex = 2;\n        \n        for(int r = 0; r < rows; r++){\n            for(int c = 0; c < cols; c++){\n                if(grid[r][c] != 1) continue;\n                \n                //save the area of this ones island in unique index\n                areas[areaIndex] = getArea(grid, r, c, areaIndex);\n                areaIndex++;\n            }\n        }\n        \n        int maxArea = 0;\n        //max area without toggling zero\n        for(int area : areas) maxArea = Math.max(area, maxArea);\n        \n        \n        //max area after toggling zero to one\n        for(int r = 0; r < rows; r++){\n            for(int c = 0; c < cols; c++){\n                if(grid[r][c] != 0) continue;\n                \n                Set<Integer> seenIsland = new HashSet();\n                \n                int area = 1;\n                for(int[] dir : DIRECTIONS){\n                    int x = r + dir[0];\n                    int y = c + dir[1];\n                    \n                    if(isOutsideGrid(x, y)) continue;\n                    \n                    if(seenIsland.contains(grid[x][y])) continue;\n                    \n                    //mark as seen this island\n                    seenIsland.add(grid[x][y]);\n                    \n                    //add the island area of current direction\n                    area += areas[grid[x][y]];\n                }\n                \n                maxArea = Math.max(area, maxArea);\n            }\n        }\n        \n        return maxArea;\n    }\n    \n    \n    private int getArea(int[][] grid, int r, int c, int areaIndex){\n        if(isOutsideGrid(r, c)) return 0;\n        \n        if(grid[r][c] != 1) return 0;\n\n        //marked Visited and assign a unique index,\n        grid[r][c] = areaIndex;\n\n        int area = 1;\n\n        for(int[] dir : DIRECTIONS){\n            int x = r + dir[0];\n            int y = c + dir[1];\n\n            area += getArea(grid, x, y, areaIndex);\n        }\n\n        return area;\n    }\n        \n    private boolean isOutsideGrid(int r, int c){\n        return r < 0 || r >= rows || c < 0 || c >= cols;\n    }\n}\n```
['Java']