Skip to main content
easyNeetCode 150

Happy Number

Given a positive integer n Return true if n is a happy number, false otherwise A happy number is defined by repeatedly replacing the number by the sum of the squares of its digits until it equals 1 (happy) or loops endlessly in a cycle (not happy) Example: n = 19 => true (1^2 + 9^2 = 82, 8^2 + 2^2 = 68, ..., eventually reaches 1) Example: n = 2 => false (loops in a cycle)

Happy Number rewards a clean two-pointer invariant instead of checking every combination. It's a great warm-up that builds invariant-driven scanning without a ton of moving parts. The trap is moving the wrong pointer and silently skipping the real answer.

Arrays & HashingTwo PointersMath & Geometry

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Check If Happy Numbereasy
Based onLeetCode