The Time Loop Puzzle
Medium
recursion
digit-sum
simulation
counting
Problem Description
A function f(n) recursively calls itself until the sum of digits of n becomes a single digit. Count the total number of function calls made.
Input Format
A single positive integer n.
Output Format
Total number of function calls made until single digit is reached.
Constraints
• 1 ≤ n ≤ 10^9
• Count includes the initial call
• Single digit means 0-9
• Sum digits repeatedly until single digit
• Example: 999 → 27 → 9 (3 calls total)
Sample Input/Output
Input:
999
Output:
3
Explanation
f(999): sum=27, call f(27). f(27): sum=9, call f(9). f(9): single digit, stop. Total calls: 3.
Solution Hints
100
Points
Points
2000ms
Time Limit
Time Limit
128MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now