Ctrl K

Keypad Words

Medium
On an old push-button phone, each digit from 2 to 9 carries a few letters: | Key | Letters | |---|---| | 2 | abc | | 3 | def | | 4 | ghi | | 5 | jkl | | 6 | mno | | 7 | pqrs | | 8 | tuv | | 9 | wxyz | The string keys is a sequence of pressed keys. Return every word it can type: one letter from each key, in the same order. If keys is empty, return an empty list. The words may be listed in any order.
Example 1
keys="58" → ['jt', 'ju', 'jv', 'kt', 'ku', 'kv', 'lt', 'lu', 'lv']

Key 5 holds j, k, l and key 8 holds t, u, v, giving 3 × 3 = 9 words.

Example 2
keys="7" → ['p', 'q', 'r', 's']

Key 7 carries four letters, so there are four words.

Example 3
keys="" → []

No keys pressed, so the list is empty.

Constraints
  • 0 ≤ len(keys) ≤ 4
  • Every character of keys is a digit from 2 to 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindromes From a Set of Letters MediumDoes the String Fit the Letter Template MediumNext Time From the Same Digits MediumCount the Tile Sequences MediumEvery Rewording of a Sentence Medium
loading Python…
Input
keys="58"
Expected
['jt', 'ju', 'jv', 'kt', 'ku', 'kv', 'lt', 'lu', 'lv']

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.