Code Room
CodingEasycod-g176
Subject MathLevel Entry–Mid~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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) → bool
Examples
in[19]outtrue
What 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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.