Digit Counter - III

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

The number 0 contains one digit.

Note:

A normal iterative or built-in 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 = 12345

Output: 5

Explanation: The number 12345 contains five digits.

Example 2:

Input: N = 0

Output: 1

Explanation: The number 0 is treated as a one-digit number.

Now Your Turn!

Pick the correct output for the given input

Input: N = 1000

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 countDigits(int N) {
// Your code goes here
}
};
Test Case

Input:

N