The "Letter Combinations of a Phone Number interview question" is one of the most famous coding challenges. Given a string of digits from 2-9 inclusive (like on a phone keypad), you need to return all possible letter combinations that the number could represent. Each digit maps to a set of letters (e.g., 2 -> "abc", 3 -> "def"). This "Letter Combinations of a Phone Number coding problem" is the quintessential backtracking exercise.
Virtually every major tech company, from Google to Amazon, has asked this question. It tests your ability to handle "Backtracking interview pattern" logic and "Hash Table interview pattern" (for mapping digits to letters). It also evaluates your ability to handle recursive branching and nested structures, which are fundamental to complex software systems.
Backtracking is the standard approach. You use a hash map to store the digit-to-letter mappings. Then, you use a recursive function that takes the current combination and the index of the digit being processed. For the current digit, you loop through its corresponding letters, append one to the combination, and recurse for the next index. After the recursion returns, you backtrack (remove the character) to try the next letter.
Digits: "23"
StringBuilder or list of characters.This is a "must-know" problem. If you can explain and implement this clearly, you demonstrate a solid grasp of recursive thinking. Pay attention to how the recursion depth matches the length of the input string.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Word Pattern II | Medium | Solve | |
| Split a String Into the Max Number of Unique Substrings | Medium | Solve | |
| Palindrome Permutation II | Medium | Solve | |
| Letter Tile Possibilities | Medium | Solve | |
| Find Unique Binary String | Medium | Solve |