Happy Number Problem

Happy Number Problem — ExecCode Easy DSA Practice

Solve the Happy Number problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A happy number is defined by repeatedly replacing the number with the sum of the squares of its digits until it becomes 1 (happy) or loops endlessly in a cycle (unhappy). Return true if n is happy.

Examples

Input n = 19; Output true

Constraints

1 ≤ n ≤ 2^31 - 1

Practice Happy Number free on ExecCode. Browse DSA problems, topic map, and placement guides.