Letter Combinations of a Phone Number - Problem
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Digit Mapping:
- 2: ABC
- 3: DEF
- 4: GHI
- 5: JKL
- 6: MNO
- 7: PQRS
- 8: TUV
- 9: WXYZ
Input & Output
Example 1 — Two Digits
$
Input:
digits = "23"
›
Output:
["ad","ae","af","bd","be","bf","cd","ce","cf"]
💡 Note:
Digit 2 maps to 'abc', digit 3 maps to 'def'. Each letter from 2 combined with each letter from 3 gives 3×3=9 combinations.
Example 2 — Empty Input
$
Input:
digits = ""
›
Output:
[]
💡 Note:
Empty input string returns empty array as no digits to process.
Example 3 — Single Digit
$
Input:
digits = "2"
›
Output:
["a","b","c"]
💡 Note:
Single digit 2 maps to letters 'a', 'b', 'c', so return each letter as separate combination.
Constraints
- 0 ≤ digits.length ≤ 4
- digits[i] is a digit in the range ['2', '9']
Visualization
Tap to expand
Understanding the Visualization
1
Input
String of digits 2-9, each mapping to letters
2
Mapping
Each digit maps to 3-4 letters like phone keypad
3
Combinations
Generate all possible letter combinations
4
Output
Array of all valid combinations
Key Takeaway
🎯 Key Insight: Each digit choice creates multiple branches - systematically explore all combinations using backtracking or iterative building
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code