LeetCode 17. Letter Combinations of a Phone Number
🧩 Problem Description
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.
💬 Example
1 | Input: digits = "23" |
💡 Approach: Backtracking
This is a classic backtracking problem.
Each digit corresponds to a set of characters (phone keypad mapping).
We explore all possible combinations by building strings recursively.
🔢 Java Code
1 | import java.util.*; |
⏱ Complexity Analysis
- Time: O(4^n) → each digit can map to up to 4 letters
- Space: O(n) recursion depth
✍️ Summary
- Maps digits to characters based on phone keypad.
- Uses backtracking to explore all valid combinations.
- Very common interview question.
Related problems:
lc-22
— Generate Parentheseslc-39
— Combination Sumlc-46
— Permutationslc-78
— Subsets