A kiosk's on-screen keypad only shows some digit keys, given in keys as strings in increasing order (never "0"). A visitor can type any positive number using only those keys, pressing a key as often as they like.
Write countTypable(keys, n) that returns how many positive integers from 1 to n can be typed.
Input: keys = ["2","5"], n = 30 Output: 4
2, 5, 22, and 25.
Input: keys = ["7"], n = 6 Output: 0
The smallest typable number is 7.
1 <= keys.length <= 9keys holds digits from "1" to "9", in increasing order, no repeats1 <= n <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #563 Numbers From a Limited Keypad. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.