Letter Combinations of a Phone Number

Medium

Description

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. Mapping: 2-abc, 3-def, 4-ghi, 5-jkl, 6-mno, 7-pqrs, 8-tuv, 9-wxyz.

Examples

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

All combinations of letters for digits 2 and 3.

Input:digits = ""
Output:[]
Explanation:

Empty input returns empty array.

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

Letters mapped to digit 2.

Constraints

  • 0 ≤ digits.length ≤ 4
  • digits[i] is a digit in the range ['2', '9'].

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!