Letter Combinations of a Phone Number - Coding Interview Problem
Last modified: April 7, 2023
Problem Description
Given a string digits
containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. The mapping of digits to letters is as follows:
{ "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz" }
Constraints:
0 <= digits.length <= 4
digits[i]
is a digit from'2'
to'9'
.
Example 1
Input: digits = "23"
Result: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2
Input: digits = ""
Result: []
Example 3
Input: digits = "2"
Result: ["a","b","c"]