Union-Find Algorithm O(NLogN) Easy
\nclass Solution {\npublic:\n    int parent[100001];\n    int rank[100001];\n    \n    int findparent(int node){\n        if(parent[node]==node){\n            r
```\nclass Solution {\npublic:\n    int parent[100001];\n    int rank[100001];\n    \n    int findparent(int node){\n        if(parent[node]==node){\n            return node;\n        }\n        \n        return parent[node]=findparent(parent[node]);\n    }\n    \n    void unionp(int x,int y){\n        x=findparent(x);\n        y=findparent(y);\n        if(x==y){\n            return;\n        }\n        if(rank[x]>rank[y]){\n               parent[y]=x;\n        }else if(rank[x]<rank[y]){\n               parent[x]=y;\n           \n        }else{\n               parent[x]=y;\n               rank[y]++;\n           \n        }\n    }\n    \n    int largestComponentSize(vector<int>& nums) {\n        for(int i=0;i<100001;i++){\n            rank[i]=0;\n            parent[i]=i;\n        }\n        for(int i=0;i<nums.size();i++){\n            for(int j=2;j<=sqrt(nums[i]);j++){\n                if(nums[i]%j==0){\n                    unionp(nums[i],j);\n                    unionp(nums[i],nums[i]/j);\n                }\n            }\n        }\n        int maxsize=0;\n        map<int,int> m;\n        for(int i=0;i<nums.size();i++){\n           int x=findparent(nums[i]);\n            m[x]++;\n            if(maxsize<m[x]){\n                maxsize=m[x];\n            }\n           \n        }\n        return maxsize;\n        \n    }\n};\n```
['Union Find', 'C', 'C++']