HARDasked at 2 companies

The Number of Good Subsets

A hard-tier problem at 36% community acceptance, tagged with Array, Math, Dynamic Programming. Reported in interviews at Lowe's and 1 others.

Founder's read

The Number of Good Subsets is a hard problem asking you to count subsets where every element is prime and the product has no repeated prime factors. With a 36% acceptance rate, it's rare and brutal. Lowe's and Media.net have both asked it. The catch: brute-force subset enumeration times out instantly on even modest input sizes. You need to recognize the bitmask constraint hidden in the problem statement and realize that dynamic programming over prime factorizations, not raw subsets, is the only path forward. If you hit this live and freeze on the approach, StealthCoder surfaces the solution invisible to the proctor.

Companies asking
2
Difficulty
HARD
Acceptance
36%

Companies that ask "The Number of Good Subsets"

If this hits your live OA

The Number of Good Subsets is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The trap most candidates fall into is trying to generate and filter all 2^n subsets, which is catastrophic. The real insight is that each valid subset corresponds to a unique bitmask of prime factors (2, 3, 5, 7, 11, 13, 17, 19, 23, 29), and you count ways to build those masks using dynamic programming. Since the input is constrained to small integers, the number of valid prime combinations is actually tiny. The problem becomes: for each number 1 to 30, precompute its prime factorization as a bitmask, then DP on which masks are reachable without colliding factors. Array manipulation and bit operations intertwine here; careless bitwise logic kills your answer. StealthCoder handles the bitmask state transitions and combinatorial counting in one solve.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

The Number of Good Subsets recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

The Number of Good Subsets interview FAQ

What's the actual trick to this problem?+

Stop thinking about subsets. Think about bitmasks of primes. Each number 2-30 has a prime factorization that fits in 10 bits (one per prime 2-29). A valid subset is one where no prime bit overlaps, so you DP on reachable bitmasks, counting the ways to reach each state using multiplication principle.

Is this really asked at Lowe's and Media.net?+

Yes. Both companies appear in the report for this problem. It's a hard-tier algorithmic challenge, so expect it only in final-round or specialist role onsites. Most general SWE interviews skip it entirely.

Why does the naive subset approach fail?+

If the input size is n=30 or larger, there are 2^30+ possible subsets. You cannot enumerate and check them all before timeout. You must recognize the constraint that valid subsets are sparse (defined by non-overlapping prime factors), then count them algebraically.

How does bit manipulation connect to dynamic programming here?+

Each number's prime factorization is a bitmask. DP state is the current bitmask of primes used so far. Transition checks if adding a new number XORs cleanly (no shared bits), then you count combinations. Without bitmask, tracking prime constraints becomes unwieldy.

Is this problem still being asked in 2024?+

It appears in recent reports from Lowe's and Media.net, but frequency is low given the 36% acceptance rate and hard difficulty. It's a specialized problem; prepare for it only if you've seen patterns in your target company's question bank.

Want the actual problem statement? View "The Number of Good Subsets" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.