‹ DS&A interview · Socratic
DSA · Backtracking · #98

Letter Combinations of a Phone Number

Module 52 · difficulty 3/5·30:00starts on first keystroke

Given a string `digits` containing digits from `2`-`9`, return all possible letter combinations the number could spell, using the standard telephone keypad mapping. Return the answer in **any order**. Keypad mapping: `2`→`abc`, `3`→`def`, `4`→`ghi`, `5`→`jkl`, `6`→`mno`, `7`→`pqrs`, `8`→`tuv`, `9`→`wxyz`. Implement `letterCombinations(digits)` returning an array of strings. If `digits` is empty, return an empty array `[]`.

Examples
  • digits = "23" ["ad","ae","af","bd","be","bf","cd","ce","cf"]2→abc, 3→def; take one letter from each digit's set.
  • digits = "" []No digits means no combinations.
  • digits = "2" ["a","b","c"]Single digit yields each of its letters.
Constraints
  • · 0 <= digits.length <= 4
  • · digits[i] is a digit in the range ['2', '9'].
  • · The keypad mapping is fixed and does not include 0 or 1.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.