JAVA || Simple Easy To Understand Using DSU
```\n// Approach :- 1. First find the maxSize among the number of islands without updating any value, can be done easily by maintaining size array in dsu.\n// 2
```\n// Approach :- 1. First find the maxSize among the number of islands without updating any value, can be done easily by maintaining size array in dsu.\n// 2. After finding maxSize, now time to check which zero will help in making greater size, this can be done easily with the of help size array of dsu.\n// 3. we maintain  set to store the visited parent / root and set will automatically remove duplicate roots\n// 4 and at last update maxSize by traversing the set and get the value of root/ parent from parent array\n\nclass Solution {\n    int[] par, size;\n    int maxSize = -(int)1e9;\n    public int findPar(int u){\n        return par[u] == u ? u : (par[u] = findPar(par[u]));\n    }\n    public void union(int[][] grid, int i, int j, int[][] dir){\n        int n = grid.length;\n        int p1 = findPar(i * n + j);\n        for(int[] d : dir){\n            int r = i + d[0];\n            int c = j + d[1];\n            if(r >= 0 && c >= 0 && r < n && c < n && grid[r][c] == 1){\n                int p2 = findPar(r * n + c);\n                if(p1 != p2){\n                    par[p2] = p1;\n                    size[p1] += size[p2];\n                }\n            }\n            maxSize = Math.max(maxSize, size[p1]);\n        }\n    }\n    public int largestIsland(int[][] grid) {\n        int n = grid.length;\n        int[][] dir = {{1,0},{0,1},{-1,0},{0,-1}};\n        par = new int[n * n];\n        size = new int[n * n];\n        for(int i = 0; i < n * n; i++){\n            par[i] = i;\n            size[i] = 1;\n        }\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++){\n                if(grid[i][j] == 1){\n                    union(grid, i, j, dir);\n                }\n            }\n        }\n// here finding which zero make greater island\n//Note :- we only need size, so no need to update grid\n\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++){\n                if(grid[i][j] == 0){\n                    HashSet<Integer> set = new HashSet<>();\n                    for(int[] d : dir){\n                        int r = i + d[0];\n                        int c = j + d[1];\n                        if(r >= 0 && c >= 0 && r < n && c < n && grid[r][c] == 1){\n                            int p = findPar(r * n + c);\n                            if(!set.contains(p))\n                                set.add(p);\n                        }\n                    }\n                    int currSize = 1;\n                    for(int p : set)\n                        currSize += (size[p]);   \n        \n                    maxSize = Math.max(currSize, maxSize);\n                }\n            }\n        }\n        return maxSize;\n    }\n}
['Union Find', 'Java']