Largest Component Size by Common Factor
Given an array nums of unique positive integers, build a graph with one node per value; connect two values with an edge if they share a common factor greater than 1. Return the size of the largest connected component of this graph.
Open official problem prompt ↗Find the size of the largest group of numbers that are transitively linked by shared prime factors.
Think of primes as clubs. Every number joins the club of each prime that divides it. People in overlapping clubs form one big social circle; we want the biggest circle.
- Input
- nums = [4,6,15,35]
- Output
- 4
- Why
- 4-6 share 2, 6-15 share 3, 15-35 share 5, so all four values are transitively connected into one component of size 4.
1 <= nums.length <= 2 * 10^41 <= nums[i] <= 10^5All values in nums are unique