Repeated sum of digits
Basic Accuracy: 33.32% Submissions: 18 Points: 1

Given an integer N, recursively sum digits of N until we get a single digit.  The process can be described below

If N < 10    
    digSum(N) = N
Else         
    digSum(N) = Sum(digSum(N))

 

Example 1:

Input:
N = 1234
Output:
1
Explanation:
The sum of 1+2+3+4 = 10, 
digSum(x) == 10 Hence 
ans will be 1+0 = 1

 

 

Example 2:

Input:
N = 9999
Output:
9
Explanation:
Check it yourself.

 

Your Task:

You don't need to read input or print anything. Your task is to complete the function repeatedSumOfDigits() which takes an integer N and returns the repeated sum of digits of N.

 

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

 

 

Constraints:

1 ≤ N ≤ 1000000

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.