#17

Letter Combinations of a Phone Number

Medium Backtracking over choices

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Each digit 2–9 maps to letters as on a phone keypad. Return all letter strings the digit string could represent.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: every word the digits could spell on a phone keypad.

Why this works: one recursion level per digit, one branch per letter on that key.

Example: "23"

2 → a, b, c ; 3 → d, e, fad ae af bd be bf cd ce cf

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Returning [""] for an empty input — the expected answer is an empty list.

Solve on LeetCode ↗
Complexity
  • Time: O(4^n · n).
  • Space: O(n).
Topic: Recursion & Backtracking
🎬 Episodes 29–36: video coming soon