Skip to content
CodeShare
All problems

Letter Combinations of a Phone Number

List every word a string of phone digits could spell.

MediumBacktrackingStringsHash map

Given a string of digits from 2 to 9, return every letter combination the digits could represent, using the letters on a phone keypad: 2 is abc, 3 is def, 4 is ghi, 5 is jkl, 6 is mno, 7 is pqrs, 8 is tuv and 9 is wxyz.

You can return the combinations in any order. An empty string of digits has no combinations.

Examples

Example 1
Input
digits = "23"
Output
["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
Example 2
Input
digits = ""
Output
[]
Example 3
Input
digits = "2"
Output
["a", "b", "c"]

Constraints

  • 0 <= digits.length <= 4
  • Each digit is between 2 and 9.