PIXELBANKv9.1.0
Menu

Letter Combinations of Phone Number

Given a string containing digits from 2-9, return all possible letter combinations that the number could represent (like a phone keypad).

Output each combination on a separate line, sorted lexicographically.

Mapping: 2=abc, 3=def, 4=ghi, 5=jkl, 6=mno, 7=pqrs, 8=tuv, 9=wxyz

Example:

Input:
23
Output:
ad
ae
af
bd
be
bf
cd
ce
cf
Reasoning:
  • The input string 23 is mapped to its corresponding letters: 2=abc and 3=def.
  • For each letter in abc, we combine it with each letter in def, resulting in 3â‹…3=93 \cdot 3 = 9 possible combinations.
  • These combinations are: ad, ae, af, bd, be, bf, cd, ce, cf.
  • The combinations are then sorted lexicographically, resulting in the final output: ad ae af bd be bf cd ce cf

Constraints:

  • 0 <= len(digits) <= 4
  • digits[i] is a digit in range ['2', '9']
solution.py

Test Results

0/0
Run code to see test results.