rulcode
Dashboard
Learn
Practice
Pricing
Toggle theme
Sign In
Fetching algorithms...
Happy Number Visualizer & Solution | Rulcode
Loading problem details...
rulcode
All problems
Toggle theme
Sign In
Description
Visualizations
Solutions
Submissions
166.
Happy Number
Medium
Topics
Companies
Hint
Understand Before Coding
Visualize This Problem
Open Visualizer
Draw Your Approach
Draw
Example 1:
Input:
n = 19
Output:
true
Explanation:
1^2 + 9^2 = 82 -> 8^2 + 2^2 = 68 -> 6^2 + 8^2 = 100 -> 1^2 + 0^2 + 0^2 = 1. Hence, 19 is a happy number.
Example 2:
Input:
n = 2
Output:
false
Explanation:
The sequence loops endlessly without reaching 1: 2 -> 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4. Since 4 has already been visited, a cycle is detected.
Constraints:
•
Learn
Understand the pattern
Steps to Solve
Time Complexity
O(log n)
Space Complexity
O(log n)
Topics
Companies
Hint
Use Cases
0
Code
Thinkpad