How to solve Sum of Digits Using Recursion
Calculate the sum of decimal digits in a nonnegative integer. Separate the last digit using modulo 10. The reference implementation illustrates this approach; check the example and edge cases.
Time and space complexity
O(d) time and O(d) recursion depth where d is the number of digits.
Practise and improve
Choose JavaScript, TypeScript or Python, complete the starter code, then select Run Tests. Request a hint when you need guidance, or choose View solution and confirm if you would like to study the reference implementation.