Problems > Happy Number > Editorial

Happy Number — Solution & Editorial

Back to the Problem

Iterate the digit-square-sum map with a seen-set (or Floyd cycle detection); values quickly drop below 1000, so it terminates fast.

Complexity: O(iterations) — effectively constant