Note: Instead of if (n == 0) return 0;, we can use if (n < 10) return n;, eliminating extra function calls for single-digit numbers without changing the output.
Output
15
Besides writing (n==0 , then return 0) in the code given above we can also write it in this manner , there will be no change in the output .
if (n <1 0) return n; by writing this there will be no need to call the function for the numbers which are less than 10
Time Complexity: O(log10n), Traverse through all the digits, as there are log10n bits. Auxiliary Space: O(log10n), due to recursive function calls stored in the call stack.