FastPrepHappy Number
Problems/Happy Number

Happy Number

Snowflake logoSnowflake● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A collection of interview-prep questions names the happy-number exercise. This exercise is not from one dated interview. Our version uses the usual step of squaring the decimal digits, returns true or false, and takes a positive 32-bit signed integer. The examples are ours. The named main exercise stays, while the wording, the input limits and the examples are our choices. Our version is about 90% the same as the reported question.

A positive integer is happy if repeatedly replacing it by the sum of the squares of its decimal digits eventually reaches 1. Otherwise the process repeats values forever.

Complete isHappy. Given the positive integer n, return true if its sequence reaches 1, and false otherwise. The initial value 1 is happy. Zero digits contribute zero to a transformation.

Function

isHappy(n: int) → boolean

Examples

Example 1

n = 19return = true

The sequence is 19→82→68→100→1.

Example 2

n = 2return = false

The sequence enters the repeating 4→16→37→58→89→145→42→20→4 cycle and never reaches 1.

Example 3

n = 1return = true

The starting value is already 1, so no transformation is needed.

Constraints

  • 1 <= n <= 2^31 - 1.
  • Use the ordinary base 10 digits of n; no string formatting or leading zeroes are part of the input.

More Snowflake Phone Screen questions

  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
  • Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Unique Pairs in a 2D Matrix Summing to TargetAmazon · PHONE SCREEN
  • Average Grades per StudentHartford Financial Services · PHONE SCREENHartford Financial Services interview questions
  • Sparse Vector Dot ProductWhatNot · PHONE SCREENWhatNot interview questions
  • Maximum Number of Balls in a BoxRoblox · PHONE SCREENRoblox interview questions
  • Median of Parsed Integer StringsRippling · PHONE SCREENRippling interview questions
  • First Node Two Linked Lists ShareAdobe · PHONE SCREENAdobe interview questions
  • Roman Numeral to IntegerScale AI · PHONE SCREENScale AI interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public boolean isHappy(int n) {
        // Write your code here.
    }

}
Checking account…