PYTHON SOL || UNION FIND || EXPLAINED ||
EXPLANATION\n\nUnion and Find is must !!\nOne way is to find GCD of every pair and if GCD > 1 means they have an edge so do union \nBut this method will give TL
# EXPLANATION\n```\nUnion and Find is must !!\nOne way is to find GCD of every pair and if GCD > 1 means they have an edge so do union \nBut this method will give TLE \n\nNow a better solution is by using factors\nFactors of 21 are : 3 , 7 \nFactors of 63 are : 3 , 7 , 9 , 21\n\nSo for 21 we have a child 3 and 7\nFor 63 we have child 3 \nBut 3\'s parent is 21 so 21 and 63 will be joined\n```\n\n# CODE\n```\nclass Solution:\n    def largestComponentSize(self, nums: List[int]) -> int:\n        \n        def find(node):\n            if parent[node] == -1: return node\n            else:\n                parent[node] = find(parent[node])\n                return parent[node]\n        \n        def union(idx1,idx2):\n            par1,par2 = find(idx1),find(idx2)\n            if par1!=par2:\n                if rank[par1] > rank[par2]:\n                    parent[par2] = par1\n                elif rank[par2] > rank[par1]:\n                    parent[par1] = par2\n                else:\n                    parent[par2] = par1\n                    rank[par1] += 1\n        \n        n = len(nums)\n        parent = defaultdict(lambda:-1)\n        rank = defaultdict(lambda:0)\n        for i in range(n):\n            limit = int(nums[i]**0.5)\n            for j in range(2,limit+1):\n                if nums[i] % j == 0:\n                    union(nums[i],j)\n                    union(nums[i],nums[i]//j)\n        count = defaultdict(lambda:0)\n        best = -1\n        for num in nums:\n            par = find(num)\n            tmp = count[par] + 1\n            if tmp > best: best = tmp\n            count[par] = tmp\n        return best\n```
['Union Find', 'Python', 'Python3']