Count the Number of Square-Free Subsets
A medium-tier problem at 25% community acceptance, tagged with Array, Math, Dynamic Programming. Reported in interviews at Media.net and 0 others.
Count the Number of Square-Free Subsets is a medium difficulty problem that appears deceptively simple but requires recognizing a pattern most candidates miss cold in an assessment. It's been asked at Media.net and sits at roughly 25% acceptance, which means three-quarters of people solving it live get stuck or TLE. The trick is that naive subset enumeration explodes exponentially, but the constraint space is actually tiny. If you blank on the bitmask insight during your OA, StealthCoder solves it invisibly while you stay cool.
Companies that ask "Count the Number of Square-Free Subsets"
Count the Number of Square-Free 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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe problem is a dynamic programming problem disguised as a combinatorics problem. The naive approach, generate all 2^n subsets and check each for square-free divisibility, fails on time. The actual solution leverages the fact that only prime factors matter, and there are only 10 primes below 30 (2, 3, 5, 7, 11, 13, 17, 19, 23, 29). This maps to a 10-bit bitmask representing which primes are already used. DP state is: dp[mask] = count of square-free subsets with that prime-usage pattern. You iterate through the array, update the mask for each number by encoding its prime factors, and skip numbers with repeated prime factors. StealthCoder handles the bit-twiddling and state transitions when you hit this wall during the assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count the Number of Square-Free Subsets recycles across companies for a reason. It's medium-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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count the Number of Square-Free Subsets interview FAQ
Why does a brute-force subset approach fail here?+
With array size up to 30, you'd enumerate 2^30 subsets and factorize each one. That's over a billion operations. The problem is solvable only when you realize the constraint is on prime factors, not array elements, collapsing the state space to 2^10 bitmask states.
What exactly is a square-free number?+
A number with no repeated prime factors. 12 = 2^2 * 3 is not square-free (2 appears twice). 30 = 2 * 3 * 5 is square-free. A square-free subset is one where no prime factor appears more than once across all chosen elements combined.
How does bit manipulation connect to the solution?+
Each number from 1 to 30 gets encoded as a 10-bit mask representing which of the 10 primes divide it. A subset is valid if the bitwise OR of all its masks has no bit set twice. DP transitions use AND/OR operations to track prime usage, making bit manipulation central to the algorithm.
Is this still asked at tech companies?+
Media.net has asked it. It's a LeetCode medium with under 26% acceptance, so it's not mainstream FAANG fare but appears in targeted assessments. Expect it more in companies running specialized coding rounds rather than leetcode-heavy pipelines.
What's the time complexity of the correct solution?+
O(n * 2^10) where n is array length and 2^10 is the number of possible bitmasks. With n up to 30, that's roughly 30,000 operations, fast enough to pass. The space is O(2^10) for the DP array, which is just 1024 entries.
Want the actual problem statement? View "Count the Number of Square-Free Subsets" on LeetCode →