Skip to main content

Cisco

Cisco OA 2023 - Happy Number

In Theoretical Mathematics, 'Happy Number' is defined as the number that when repeatedly replaced with a number equal to the sum of the square of all its
digits, leads us back to '1'. Rest of the numbers will never reach '1' AND will be stuck in a cycle of numbers that does not include '1'.

Write a program to find the MAXIMUM size of the set of UNIQUE happy numbers between X and Y. Return 0 is none exist. A happy number is said to be UNIQUE in
a set if there is no other number in that set which is
a combination of the digits of the said happy number.

Input
There are two numbers X and Y representing the low and high end of the range. The range includes X and Y.

The first line represents the low end i.e. X.
The second line represents the high end i.e. Y.

Output
Maximum size among the subsets of a set of UNIQUE happy numbers.

Constraints:
0 <= X,Y <= 10^5