Back to course home
0% completed
Vote For New Content
Letter Combinations of a Phone Number (medium)
Problem Statement
Given a string digits
containing digits from 2-9, return an array of strings containing all possible letter combinations
that the number could represent. You may return the answer in any order
.
The mapping of digits
to letters
(just like on the telephone buttons
) is as given below.
1
-> It doesn't map any number.2
-> "abc"3
-> "def"4
-> "ghi"5
-> "jkl"6
-> "mno"7
-> "pqrs"8
-> "tuv"9
-> "wxyz"
Examples
-
Example 1:
- Input: digits =
"47"
- Expected Output:
["gp", "gq", "gr", "gs", "hp", "hq", "hr", "hs", "ip", "iq", "ir", "is"]
- Justification: The digit '4' maps to "ghi", and '7' maps to "pqrs". Combining these letters in every possible way gives us the expected output.
- Input: digits =
-
Example 2:
- Input: digits =
"29"
- Expected Output:
["aw", "ax", "ay", "az", "bw", "bx", "by", "bz", "cw", "cx", "cy", "cz"]
- Justification: The digit '2' maps to "abc", and '9' maps to "wxyz". The combinations of these letters result in the expected output.
- Input: digits =
-
Example 3:
- Input: digits =
"7"
- Expected Output:
["p", "q", "r", "s"]
- Justification: The digit '7' maps to "pqrs". All possible combinations of these letters are reflected in the expected output.
- Input: digits =
Constraints:
- 0 <= digits.length <= 4
- digits[i] is a digit in the range ['2', '9'].
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself