Please read the instructions carefully before starting the exam.
Once you start the exam, the timer will begin, and you cannot pause it.
Ensure that you complete and submit your code within the given time if the timer is enabled.
Imagine you are working for a company that processes large sets of customer data.
One of the tasks involves calculating a special “digit sum score” for each customer based on their unique ID number.
The score is simply the sum of all digits in the customer’s ID.
You have been asked to create a function that calculates this digit sum for any given ID number, which can be as long as 18 digits.
The function should be implemented using recursion, as it will be reused in other recursive tasks in the system.
Write a recursive function to compute the sum of digits for a given customer ID number.
n
representing the customer’s ID number, where 1 ≤ n ≤ 1018
.Return an integer representing the sum of the digits of the customer’s ID.
n
will not contain any leading zeros.Input: n = 76345 Output: 25 Explanation: The sum of the digits 7 + 6 + 3 + 4 + 5 = 25
Input: n = 8 Output: 8 Explanation: Since there is only one digit, the sum is 8.
Input: n = 1000000001 Output: 2 Explanation: The sum of the digits 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 = 2
Input: n = 98765432123456789 Output: 90 Explanation: The sum of the digits 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 90
The function should be able to handle very large ID numbers quickly and efficiently using recursion, and it will be part of a larger customer data processing system.