Letter Combinations of a Phone Number - aloalgo

Letter Combinations of a Phone Number

Hard

You are given a string containing digits from 2-9 inclusive, find and return all possible letter combinations that the number could represent. Return the answer in any order.

A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

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

Example 1

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

Digit '2' maps to 'a', 'b', 'c'. Digit '3' maps to 'd', 'e', 'f'. Combining these, we get 'ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'.

Example 2

Input
""
Output
[]
Explanation:

An empty input string results in an empty list of combinations.

Example 3

Input
"2"
Output
["a", "b", "c"]
Explanation:

Digit '2' maps to 'a', 'b', 'c'.

Loading...
Input
"23"
Output
["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!