Letter Combinations of a Phone Number
On an old phone keypad each digit from 2 to 9 stands for three or four letters. You get a string of such digits; return every word you can type with it, one letter per digit, in any order, and nothing for an empty string. Our example: "38", where 3 is d, e, f and 8 is t, u, v, gives 9 words: dt, du, dv, et, eu, ev, ft, fu, fv.
| 1— | 2abc | 3def |
| 4ghi | 5jkl | 6mno |
| 7pqrs | 8tuv | 9wxyz |
- input
digits: a string of digits from'2'to'9', maybe empty; each digit stands for the letters of its key on the keypad above.- returns
- Every string the digits can type: one letter from each digit's button, in the order of the digits. For an empty
digits, an empty list. The strings in any order. - constraints
- 0 ≤ digits.length ≤ 4
- digits[i]: a digit from '2' to '9'
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} digits
* @return {string[]}
*/
function letterCombinations(digits) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more backtracking problems
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.