Letter Combinations of a Phone Number

Medium Solved

Description

Given a string containing digits from 2 to 9, return all possible letter combinations that the number could represent.

A mapping of digits to letters (like on a phone keypad) is given below. Note that 1 does not map to any letters.

Input format / Clarification:

  • Line 1: String digits

Examples

Input:
"23"
Output:
["ad","ae","af","bd","be","bf","cd","ce","cf"]
Input:
""
Output:
[]
Input:
"2"
Output:
["a","b","c"]

Note:

Output must be printed as a JSON array of strings.
print(str(fuctionname(x)).replace(" ", "")) In Python

No submissions yet.

Discuss backtracking, recursion depth, and iterative BFS approaches.

Test Cases