Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Letter Combinations of a Phone Number

Medium
backtrackingstringhash-table

Given a string of digits 2–9, return all letter combinations the number could represent on a classic phone keypad (2=abc, 3=def, 4=ghi, 5=jkl, 6=mno, 7=pqrs, 8=tuv, 9=wxyz).

Input: one line, the digit string (may be empty). Output: one combination per line (nothing for an empty input). Any order — printed canonically.

Example 1
Input:
23
Output:
ad
ae
af
bd
be
bf
cd
ce
cf
Example 2
Input:
2
Output:
a
b
c

Constraints

  • 0 ≤ digits.length ≤ 4
  • Digits 2–9 only.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.