Happy number
A happy number is defined by repeatedly replacing the number with the sum of the squares of its digits; if this process eventually reaches 1 the number is happy, otherwise it loops forever in a cycle that never includes 1. Given a positive integer n (1 <= n <= 2^31 - 1), return True if n is happy and False otherwise. For example 19 -> 1+81+1+81 ... -> 1, so 19 is happy.
Implement
is_happy_number(n: int) → boolExamples
in
[19]outtrueWhat a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 15 min
solution.py
InputExpectedGot
[19]truenot run yetsample