Pattern Recognition Drill
Easy Math & Geometry
The Problem
Determine if a number is 'happy': repeatedly sum the squares of its digits; if it reaches 1 it's happy.
What approach would you use?
Think about it before scrolling down.
Track seen numbers. If you see a repeat, it's a cycle → not happy. O(log n) per step.
Floyd's slow/fast on the digit-sum function. Detects cycle without extra space.
Common Trap
Don't assume it always converges quickly. The cycle detection is essential to avoid infinite loops.