Times a Digit Is Written
Write out every whole number from 1 to n. Return how many times the digit d gets written.
Example 1
n 13
d 1
returns 6
The digit 1 is written in 1, 10, 11 (twice), 12 and 13.
Example 2
n 10
d 0
returns 1
Only 10 has a 0.
Constraints
1 <= n <= 10**90 <= d <= 9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Ways as a Run of NumbersHard
- Alternating Digit SumBeginner
- Armstrong NumberBeginner
- Base K to DecimalBeginner
- Collatz StepsBeginner
- Count DivisorsBeginner
- Decimal to Binary StringBeginner
- Digit Sum in Base KBeginner