Question bank › Math
Dsa Math Hard

Happy Number Differentiation

A happy number is defined by the following process: repeatedly replace the number with the sum of the squares of its digits until the number equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Write a program that determines if a number N is happy or not. The input consists of a single integer N (1 <= N <= 10^6). Output 'HAPPY' if it is happy and 'SAD' otherwise. Example Input: 19 Example Output: HAPPY

Key concepts

number theorymathhappy numbers

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.