
Problem
Solution
Submissions
Letter Combinations of a Phone Number
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a C program to find all possible letter combinations that the numbers of a given string could represent on a telephone keypad. Given a string containing digits from 2-9, return all possible letter combinations that the number could represent. The mapping of digits to letters is the same as on telephone buttons (as shown below): - 2: abc - 3: def - 4: ghi - 5: jkl - 6: mno - 7: pqrs - 8: tuv - 9: wxyz
Example 1
- Input: digits = "23"
- Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
- Explanation:
The digit '2' corresponds to letters 'a', 'b', 'c'. The digit '3' corresponds to letters 'd', 'e', 'f'.
All possible combinations are: "ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf".
Example 2
- Input: digits = "5"
- Output: ["j", "k", "l"]
- Explanation:
The digit '5' corresponds to letters 'j', 'k', 'l'.
Since there is only one digit, the combinations are simply the letters themselves.
Constraints
- 0 <= digits.length <= 4
- digits[i] is a digit in the range ['2', '9']
- Time Complexity: O(4^n) where n is the length of digits
- Space Complexity: O(n) for recursion stack
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use a mapping of digits to their corresponding letters
- Use backtracking or recursion to generate all possible combinations
- For each digit, try all its corresponding letters and proceed to the next digit
- Use a temporary string to build each combination
- When the combination's length equals the input's length, add it to the result