EvalFrame Technical Mock Interviews & Coding Practice

Letter Combinations of a Phone Number

Medium · Recursion / Backtracking · Algorithm problem · all problems

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. A mapping of digits to letters (just like on the telephone buttons) is given below: 2: abc, 3: def, 4: ghi, 5: jkl, 6: mno, 7: pqrs, 8: tuv, 9: wxyz. **Examples:** ```typescript letterCombinations("23") // ["ad","ae","af","bd","be","bf","cd","ce","cf"] letterCombinations("") // [] letterCombinations("2") // ["a","b","c"] ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(4^n)
  • Space complexity: O(n)

Each digit maps to at most 4 letters, producing at most 4^n combinations.

Follow-Up Questions Interviewers Ask About Letter Combinations of a Phone Number

  • Can this be implemented iteratively?
    Yes, using BFS with a queue or reducing over the digits array to compute cross-products.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.