Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Repetitive Addition Of Digits
Basic Accuracy: 56.71% Submissions: 240 Points: 1

Given a non-negative integer N, repeatedly add all its digits until the result has only one digit.

Example 1:

Input:
N = 98

Output:
8

Explanation:
Sum of digit of N = 98  is 9 + 8 = 17
Sum of digit of 17 = 1 + 7 = 8
Since 8 is the single digit number hence it is the 
required answer.

Example 2:

Input:
N = 1

Output:
1

Explanation:
Since 1 is the single-digit number hence it is the 
required answer.

Your Task:  
You don't need to read input or print anything. Your task is to complete the function singleDigit() which takes an integer N as an input parameter and return the single-digit you will get after repeatedly adding the digits of N.

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

Constraints:
1 <= N <= 1018

 

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.

Repetitive Addition Of Digits

Output Window