Letter Combinations of a Phone Number
Given digits 2-9, return all possible letter combinations.
Examples
Input: "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Input: ""
Output: []
Hints
Map each digit to its corresponding letters (e.g., '2' → ['a', 'b', 'c']) and store these mappings in a dictionary for quick lookup.
Use backtracking to explore all possible combinations by iterating through each digit's letters and recursively building the current combination until all digits are processed.
Handle edge cases (e.g., empty input) by returning an empty list immediately, and optimize space by avoiding unnecessary string copies during recursion (e.g., using a mutable list to build combinations).
Related Problems
Letter Combinations of a Phone Number
Given digits 2-9, return all possible letter combinations.