Skip to content
Onsite

Letter Combinations of a Phone Number

MediumP2Coding

digits contains digits from 2 to 9. Using the classic phone keypad mapping (2: abc, 3: def, 4: ghi, 5: jkl, 6: mno, 7: pqrs, 8: tuv, 9: wxyz), return every string that the digits could spell, in any order.

If digits is empty, return an empty array.

Example 1

Input
digits = "23"
Output
["ad","ae","af","bd","be","bf","cd","ce","cf"]
Why
3 letters times 3 letters gives 9 strings.

Example 2

Input
digits = ""
Output
[]

Example 3

Input
digits = "2"
Output
["a","b","c"]

Constraints

  • 0 <= digits.length <= 6
  • digits contains only the characters 2 to 9.

Hints

Run checks the 3 visible tests, Submit all 10.