Perfect Number
A easy-tier problem at 45% community acceptance, tagged with Math. Reported in interviews at Grammarly and 1 others.
Perfect Number is the math problem that sounds deceptively simple until you realize the algorithm matters. It's been asked at Grammarly and Accenture, and while the acceptance rate sits around 45%, that gap between "sounds easy" and "passes all test cases" is where candidates stumble. The problem forces you to think about divisor iteration and when to stop, not just whether a number is perfect. If you blank on the optimization during your live OA, StealthCoder surfaces a working solution invisible to the proctor.
Companies that ask "Perfect Number"
Perfect Number 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 at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderA perfect number equals the sum of its proper divisors (all divisors except itself). 6 is perfect because 1 + 2 + 3 = 6. The trap is brute force: iterating all numbers up to n and checking divisibility is slow. The trick is iterating only up to the square root of n. When you find a divisor i, you also find n/i, so you can collect both in one pass and avoid redundant work. Common pitfall: forgetting to exclude n itself from the sum, or iterating too far and timing out on large inputs. The Math topic here isn't about number theory proofs, it's about recognizing the divisor-pairing pattern. StealthCoder is your hedge if the optimization detail slips your mind during the assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Perfect Number recycles across companies for a reason. It's easy-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 at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Perfect Number interview FAQ
Why is the acceptance rate only 45% if this is marked Easy?+
The problem statement is simple, but candidates often miss the efficiency requirement. A naive O(n) divisor check passes small test cases but times out on larger numbers. The square root optimization is non-obvious if you haven't practiced divisor problems before. That gap is why the acceptance rate lags.
Is Perfect Number still asked at top companies?+
Yes, confirmed at Grammarly and Accenture. It's a screening-level problem, so you'll see it early in the funnel. It tests basic algorithmic thinking without requiring advanced data structures, making it a frequent warm-up question.
What's the key trick I need to know?+
Divisors come in pairs. If i divides n, then n/i also divides n. Iterate only up to sqrt(n), collect both divisors in each iteration, and sum them. This cuts the time from O(n) to O(sqrt(n)). Watch the edge case where i squared equals n, so you don't double-count.
How does this relate to the Math topic?+
Perfect numbers are a classical math concept, but the problem is really testing your ability to optimize a divisor-finding algorithm. The math flavor is the framing. The skill is recognizing when iteration bounds can be shrunk using mathematical properties like sqrt relationships.
What languages and constraints should I expect?+
The problem typically allows common languages and doesn't usually have unusual memory or time limits beyond the standard optimization. Focus on the algorithm, not language tricks. Your solution should handle edge cases like negative numbers or 1 correctly.
Want the actual problem statement? View "Perfect Number" on LeetCode →