✅ [c++]  ||  Disjoint Set (Union Find) + Map
\nclass Solution {\npublic:\n    vector<int> parent;\n    vector<int> rank;\n    \n    int find(int x){\n        if(parent[x]==x) return x;\n        return pare
```\nclass Solution {\npublic:\n    vector<int> parent;\n    vector<int> rank;\n    \n    int find(int x){\n        if(parent[x]==x) return x;\n        return parent[x] = find(parent[x]);\n    }\n    \n    void unionDsu(int x, int y){\n        int _x = find(x), _y = find(y);\n        if(_x == _y) return;\n        if (rank[_x] < rank[_y]){\n            parent[_x] = _y;\n        }else if(rank[_x] > rank[_y]){\n            parent[_y] = _x;\n        }else{\n            parent[_y] = _x;\n            rank[_x]+=1;\n        }\n    }\n    \n    int largestComponentSize(vector<int>& nums) {\n        int size = *max_element(nums.begin(), nums.end());\n        parent.resize(size+1);\n        for(int i=0; i<size+1; ++i) parent[i]=i;\n        rank.resize(size+1,1);\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                    unionDsu(nums[i], j);\n                    unionDsu(nums[i]/j, j);\n                }\n            }\n        }\n        \n        unordered_map<int,int> map;\n        for(int i=0; i<nums.size(); ++i){\n            int _x = find(nums[i]);\n            map[_x]++;\n        }\n        \n        int maxCount = 0;\n        for(auto &m : map) maxCount = max(maxCount, m.second);\n        \n        return maxCount;\n    }\n};\n```\nPlease **UPVOTE**
['Math', 'Union Find', 'C', 'C++']