Skip to content

Practice Largest Component Size by Common Factor

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#952
LeetCode Problem

Largest Component Size by Common Factor

Problem Statement

Create one graph node for each unique positive value in nums. Join two nodes with an undirected edge when their values share a factor greater than 1. Return the largest number of nodes in any connected component; connection may be through intermediate values.

Source: Largest Component Size by Common Factor on LeetCode. Use the original task for its coding environment and submissions.

Examples

# 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

Constraints

1 <= nums.length <= 2 * 10^4
1 <= nums[i] <= 10^5
All the values of nums are unique.

Related LeetCode Problems

Practice more problems similar to Largest Component Size by Common Factor.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.