Happy Number
Easy · Hashing · about 10 minutes
Asked at Snowflake, Google, Microsoft, Bloomberg, Meta, Amazon, Two Sigma, CrowdStrike, Rubrik.
Take a positive integer n, square each of its digits, and add the squares up to get the next number. Keep going. If the sequence eventually hits 1, n is happy; if not, it gets stuck repeating a cycle that never contains 1. Report whether n is happy.