FunctionRacerProblemsRace

Numbers a Broken Keypad Can Type

HardMathPython, JavaScript, TypeScript, Java, C++

On a number keypad only the keys listed in digits still work. Each working key can be pressed as often as you like.

Return how many whole numbers from 1 to n can be typed.

Example 1

digits [1,3]
n 40
returns 6

The numbers are 1, 3, 11, 13, 31 and 33. Everything else up to 40 needs another key.

Example 2

digits [7,8,9]
n 100
returns 12

Three numbers of one digit and nine of two digits. 100 itself needs the keys 1 and 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