Simple C++ || Union_Find
Code\n\nclass DisjointSet {\npublic: \n    vector<int> parent, size; \n    DisjointSet(int n) {\n        parent.resize(n+1);\n        size.resize(n+1); \n      
# Code\n```\nclass DisjointSet {\npublic: \n    vector<int> parent, size; \n    DisjointSet(int n) {\n        parent.resize(n+1);\n        size.resize(n+1); \n        for(int i = 0;i<=n;i++) {\n            parent[i] = i; \n            size[i] = 1; \n        }\n    }\n\n    int findUPar(int node) {\n        if(node == parent[node])\n            return node; \n        return parent[node] = findUPar(parent[node]); \n    }\n\n    void unionBySize(int u, int v) {\n        int ulp_u = findUPar(u); \n        int ulp_v = findUPar(v); \n        if(ulp_u == ulp_v) return; \n        if(size[ulp_u] < size[ulp_v]) {\n            parent[ulp_u] = ulp_v; \n            size[ulp_v] += size[ulp_u]; \n        }\n        else {\n            parent[ulp_v] = ulp_u;\n            size[ulp_u] += size[ulp_v]; \n        }\n    }\n}; \n\nclass Solution {\npublic:\n    int largestIsland(vector<vector<int>>& grid) {\n        int n=grid.size();\n        DisjointSet ds(n*n);\n        vector<pair<int,int>> dir={{0,1},{0,-1},{1,0},{-1,0}};\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]==1){\n                    for(auto it:dir){\n                        int adjR=it.first+i,adjC=it.second+j;\n                        if(adjR>=0 && adjR<n && adjC>=0 && adjC<n && grid[adjR][adjC]){\n                            ds.unionBySize(n*adjR + adjC , n*i + j);\n                        } \n                    }\n                }\n            }\n        }\n\n        int ans=0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]==0){\n                    set<int> st;\n                    for(auto it:dir){\n                        int adjR=it.first+i,adjC=it.second+j;\n                        if(adjR>=0 && adjR<n && adjC>=0 && adjC<n && grid[adjR][adjC]){\n                            st.insert(ds.findUPar(n*adjR+adjC));\n                        }\n                    }\n                    int tmp_size=1;\n                    for(auto it:st){\n                        tmp_size+=(ds.size[it]);\n                    }\n                    ans=max(ans,tmp_size);\n                }\n            }\n        }\n        for(int i=0;i<n*n;i++){\n            ans=max(ans,ds.size[ds.findUPar(i)]);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Depth-First Search', 'Breadth-First Search', 'Union Find', 'Matrix', 'C++']