213. Count a Digit
Foundation1000 ms256 MBSolved by 0%
Print how many times the digit d appears in the number n.
n = 12321, d = 2 -> 2
n = 5, d = 7 -> 0
Strip one digit at a time, adding 1 whenever the digit you removed is d.
The input n = 0 is worth thinking about before you write the base case. Zero
contains the digit 0 once.
Constraints - `0 ≤ n ≤ 1000000000` - `0 ≤ d ≤ 9`
Input
A single line containing two integers n and d, separated by a space.
Output
Print one integer, the number of times d appears in n.
Input12321 2
Output2
Noteis the worked example
Input5 7
Output0
Notehas no occurrences at all
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.