Digit Sum - III

Given a non-negative integer N, return the sum of all digits present in N using recursion.

Note:

A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.

Example 1:

Input: N = 2917

Output: 19

Explanation: The sum of the digits is 2 + 9 + 1 + 7 = 19.

Example 2:

Input: N = 100

Output: 1

Explanation: The sum of the digits is 1 + 0 + 0 = 1.

Now Your Turn!

Pick the correct output for the given input

Input: N = 917293

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 0 <= N <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int digitSum(int N) {
// Your code goes here
}
};
Test Case

Input:

N