Perfect Squares
A medium-tier problem at 56% community acceptance, tagged with Math, Dynamic Programming, Breadth-First Search. Reported in interviews at Revolut and 5 others.
Perfect Squares shows up in live assessments at Google, Citadel, and Walmart Labs. The problem looks simple on the surface: find the least number of perfect squares that sum to a given integer. Candidates often lock into a greedy approach (always subtract the largest perfect square), which fails on cases like 7. The acceptance rate sits around 55%, meaning a solid chunk of people ship broken code under time pressure. If this problem hits your assessment and you blank on the DP recurrence, StealthCoder solves it invisibly in seconds.
Companies that ask "Perfect Squares"
Perfect Squares 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 trick is dynamic programming, not math intuition. You build a DP table where dp[i] represents the minimum number of perfect squares summing to i. For each number, you try subtracting every perfect square smaller than it and take the minimum result. BFS works too: treat each number as a node, and edges connect to numbers reachable by subtracting a perfect square. The greedy approach fails because 7 requires 4 (2^2) + 1 (1^2) + 1 + 1, not 4 + 3 attempts at 1. Candidates who skip to implementation without sketching a few examples often realize halfway through their solution won't work. StealthCoder is the hedge if the DP state transitions don't click during your time-boxed OA.
Pattern tags
You know the problem.
Make sure you actually pass it.
Perfect Squares 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.
Perfect Squares interview FAQ
Is greedy the intended solution?+
No. Greedy fails on 7 (it gives 4 + 1 + 1 + 1 instead of 4 + 1 + 1 + 1... wait, that's also four). Actually 7 = 4 + 1 + 1 + 1 is correct, but greedy also tries 7 = 4 + 3, which doesn't help. DP or BFS is required.
Do I need to optimize space for the interview?+
The standard DP solution uses O(n) space and O(n * sqrt(n)) time, which passes easily. Space optimization to O(1) isn't expected. Focus on correctness and explaining why DP state transitions work.
How does this relate to the other Math topics?+
You need to recognize perfect squares (1, 4, 9, 16, etc.) quickly, but the problem is fundamentally about minimization, not number theory. Math is a tag because you iterate over sqrt(n). DP is the actual skill being tested.
Is this still asked at top companies?+
Yes. Google, Citadel, and Walmart Labs have all reported this problem. The 55% acceptance rate suggests it's a real filter. Don't skip it in prep.
What's the common mistake during an assessment?+
Rushing to code without testing edge cases like 1, 2, 3, 7. Many candidates also forget to check if a number is already a perfect square before entering the DP loop, leading to off-by-one errors.
Want the actual problem statement? View "Perfect Squares" on LeetCode →