Letter Combinations of a Phone Number

Medium

Topics
StringBacktrackingHash Table

Given a string of digits from 2-9, return all letter combinations the number could spell (phone keypad mapping). Return an empty result for an empty input. Order does not matter.

Example 1

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

Example 2

Input:  digits = ""
Output: []

Constraints

  • 0 <= digits.length <= 4
  • digits[i] is in the range 2-9.
Run ⌘' · Submit ⌘⏎