Generate every possible letter string that a phone keypad number sequence can represent.
Given a string of digits from 2 to 9, return all possible letter combinations that the number could represent using the standard phone keypad mapping.
Each digit maps to a set of letters:
2 -> abc3 -> def4 -> ghi5 -> jkl6 -> mno7 -> pqrs8 -> tuv9 -> wxyz
Build every valid combination by choosing one letter for each digit in order. The result may be returned in any order.
If the input contains no digits, return an empty list.
Input Format
- A string
digitscontaining only characters from2to9. - Length may be zero.
Output Format
- Return a list of strings.
- Each string is one valid letter combination formed by mapping every digit to one letter and preserving the digit order.
Constraints
0 <= digits.lengthdigits[i]is in the range'2'..'9'- Order of returned combinations does not matter.
Example 1
Input
digits = "23"
Output
["ad","ae","af","bd","be","bf","cd","ce","cf"]
Explanation
Digit 2 maps to abc and digit 3 maps to def. Combine every choice from the first digit with every choice from the second digit.
Example 2
Input
digits = ""
Output
[]
Explanation
With no digits, there are no letter combinations to generate.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.