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.
Task:
Write a recursive function to compute the sum of digits for a given customer ID number.
Input:
* A positive integer n representing the customer’s ID number, where 1≤ n≤1018
Output:
* Return an integer representing the sum of the digits of the customer’s ID.
Constraints:
* The customer ID number n will not contain any leading zeros.
* The function must use recursion.
* Ensure the function is efficient enough to handle large ID numbers up to 18 digits long.
Example 1:
Input: n = 76345
Output: 25
Explanation: The sum of the digits 7+6+3+4+5=25
Example 2:
Input: n = 8
Output: 8
Explanation: Since there is only one digit, the sum is 8.
Example 3:
Input: n = 1000000001
Output: 2
Explanation: The sum of the digits 1+0+0+0+0+0+0+0+0+1=2
Example 4:
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
Note:
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.