Skip to main content

Letter Combinations of a Phone Number

MediumPremium

On a phone keypad, each digit from 2 to 9 maps to a few letters:

2: abc 3: def 4: ghi 5: jkl 6: mno 7: pqrs 8: tuv 9: wxyz

Given a string digits containing only digits from 2 to 9, return every letter string the digits could spell, taking one letter for each digit. Return the strings in any order. If digits is empty, return an empty list.

Example 1

Input: digits = "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]

Each of the three letters for 2 pairs with each of the three letters for 3.

Example 2

Input: digits = "" Output: []

Constraints

  • 0 <= digits.length <= 4
  • Each character of digits is a digit from 2 to 9.