Letter Combinations of a Phone Number
On an old phone keypad, each digit from 2 to 9 maps to a group of letters (2 → abc, 3 → def, 4 → ghi, 5 → jkl, 6 → mno, 7 → pqrs, 8 → tuv, 9 → wxyz). Given a string of such digits, return every possible string that could be typed by choosing one letter per digit, in order. Return them in any order.
The input has between 0 and 4 digits; an empty input must return an empty list (not a list containing the empty string).
Examples
- Input:
- digits = "23"
- Output:
- ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
Digit 2 offers a/b/c and digit 3 offers d/e/f: 3 × 3 = 9 combinations, each pairing one letter from each group in order.
- Input:
- digits = ""
- Output:
- []
No digits means no combinations — the answer is an empty list.
- Input:
- digits = "2"
- Output:
- ["a", "b", "c"]
A single digit yields exactly its own letters.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.