The Distinct Prime Factors of Product of Array interview question provides an array of integers and asks you to find the number of unique prime factors that would exist if you were to multiply all elements of the array together. You don't actually need to perform the multiplication (which would result in a massive overflow); you only need to identify the prime building blocks of the individual numbers.
Companies like Microsoft and Google use this to test your knowledge of Number Theory interview patterns. It evaluations whether you can break down numbers into their prime components and your understanding of prime factorization. It also tests your ability to use a Hash Set to collect unique values across multiple operations efficiently.
This problem uses Prime Factorization and a Hash Set.
HashSet.HashSet at the end is the number of distinct prime factors.Array: [2, 4, 3, 7, 10, 6]
Understand the standard prime factorization algorithm: divide by 2 while possible, then check odd numbers up to . If after the loop, the remaining is also prime. This is a foundational Math interview pattern that appears in many GCD, LCM, and factor-related problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Split the Array to Make Coprime Products | Hard | Solve | |
| Number of Pairs of Interchangeable Rectangles | Medium | Solve | |
| Largest Component Size by Common Factor | Hard | Solve | |
| Find the Count of Numbers Which Are Not Special | Medium | Solve | |
| Number of Boomerangs | Medium | Solve |