205. Count the Digits by Recursion
Foundation1000 ms256 MBSolved by 0%
Print how many digits n has.
Dividing by 10 removes the last digit, so each recursive call works on a number one digit shorter. That is your step towards the base case.
Read the constraints before choosing where to stop. n can be 0, and 0 has
one digit, not none.
Constraints - `0 ≤ n ≤ 1000000000`
Input
A single line containing one integer n.
Output
Print one integer, the number of digits in n.
Input999
Output3
Noteis a plain three-digit number
Input0
Output1
Notehas one digit, which a naive base case reports as zero
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.