#952
Largest Component Size by Common Factor
master · 1635 · lc hard +32 · verified · 42.5% accepted · 1,723 likes · top 24%
Description
Given unique positive integers nums, build an undirected graph where an edge connects two values that share a common factor greater than 1. Return the number of nodes in the largest connected component.
Example 1:
Input: nums = [4,6,15,35]
Output: 4
Example 2:
Input: nums = [20,50,9,63]
Output: 2
Example 3:
Input: nums = [2,3,6,7,4,12,21,39]
Output: 8
Code
1
2
3