Phone Keypad Letter Combinations
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The empty string is where a naive solution dies on this Google OA, reported in July 2026. Most people write the backtracking in five minutes, then return [""] for empty input and fail the first hidden test. The task is Phone Keypad Letter Combinations: map digits 2-9 to letters, return every combination in left-to-right depth-first order. Input is at most 4 digits, so size isn't the issue. Correctness on the edges is. If you freeze on the night, StealthCoder runs invisibly on the OA as a safety net, but this one is easy to own before you sit down.
The problem
Given a string digits, return every letter combination that the digits could represent on a conventional telephone keypad. 2 maps to abc, 3 to def, 4 to ghi, 5 to jkl. 6 maps to mno, 7 to pqrs, 8 to tuv, and 9 to wxyz. For this exercise, emit combinations in depth-first order, visiting each digit's mapped letters from left to right. Return an empty list for empty input. Function letterCombinations(digits: String) → List<String> Examples Example 1 digits = "23" return = ["ad","ae","af","bd","be","bf","cd","ce","cf"] Choose one of abc for the first position and one of def for the second, following left-to-right depth-first order. Example 2 digits = "" return = [] There is no position to assign, so the exercise returns an empty list. Constraints 0 <= digits.length <= 4 Every character in digits is between 2 and 9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is backtracking. Build a map from digit to letters, then recurse by index. At each index, loop over that digit's letters, append one to the current path, recurse to index+1, then pop. When the path length equals digits.length, push the joined string to the result. The pitfall is the empty input. Your base case will fire immediately at index 0 and add an empty string, but the spec says return an empty list. Guard with an early return before recursing. Second pitfall: output order. Iterating letters left to right in a plain DFS gives exactly the order in Example 1, so don't sort or use a queue that reshuffles things. With 4 digits max, the worst case is 4^4 = 256 strings, so complexity is a non-issue. If you blank mid-assessment, StealthCoder is the hedge that reads the prompt and hands you the guarded version.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Phone Keypad Letter Combinations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as letter combinations of a phone number. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Phone Keypad Letter Combinations FAQ
What's the trick in Phone Keypad Letter Combinations?+
It's backtracking over digit positions. For each index, try every mapped letter, recurse, then undo. The real trick is the empty-input guard. Return an empty list before recursing, or your base case will add a single empty string and fail the hidden test.
How hard is this Google OA question really?+
Easy to medium. The constraint is 4 digits at most, so there's no performance trap. Most failures come from the empty string case and from messing up the order. If you've written any backtracking before, it's a ten minute problem.
Does the output order matter here?+
Yes. The prompt specifies depth-first order, visiting each digit's letters left to right. A standard recursive DFS produces that naturally, giving ["ad","ae","af","bd",...] for "23". Don't sort afterward or build it with a method that changes order.
Can I solve it iteratively instead of recursively?+
You can. Start with a list holding one empty string, then for each digit expand every existing string with each mapped letter. Order stays correct if you loop existing strings outer, letters inner. Still handle empty input first by returning an empty list.
How do I prepare for this in 48 hours?+
Write the solution from memory twice. Type the digit map by hand, code the recursion with a path list and pop, and test three inputs: empty, a single digit like "7", and "23". Check that 7 and 9 have four letters each.