Numbers a Broken Keypad Can Type
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
1 <= len(digits) <= 9digitsholds different digits from 1 to 9, in any order1 <= n <= 10**15
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Smallest Factorial With K ZerosHard
- Times a Digit Is WrittenHard
- Ways as a Run of NumbersHard
- Alternating Digit SumBeginner
- Armstrong NumberBeginner
- Base K to DecimalBeginner
- Collatz StepsBeginner
- Count DivisorsBeginner