You are given an array of distinct positive integers nums.
Build a graph where:
• Each number in nums is a node.
• There is an undirected edge between nums[i] and nums[j] if they share a
common factor greater than 1.
Return the size of the largest connected group in this graph.
Input: nums = [4,6,15,35]
Output: 4
Explanation:
• Factors connect as: 4 ↔ 6 (factor 2), 6 ↔ 15 (factor 3), 15 ↔ 35 (factor 5). • All four numbers are connected through shared factors, forming a single group of size 4.
Input: nums = [20,50,9,63]
Output: 2
Explanation:
• 20 and 50 share factor 10 → group of size 2. • 9 and 63 share factor 3 → another group of size 2.
Input: nums = [2,3,6,7,4,12,21,39]
Output: 8
Accepted:
Submission: