The digital root of a non-negative integer is found by summing its digits, then summing the digits of that result, and so on, until a single digit remains.
One line: a non-negative integer n.
One line: the single-digit digital root of n.
Example 1
Input
942
Expected
6
Explanation
9+4+2=15, then 1+5=6. The digital root is 6.
Example 2
Input
0
Expected
0
Explanation
0 is already a single digit; its digital root is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →