FunctionRacerProblemsRace

Times a Digit Is Written

HardMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems