The Letter Combinations of Phone Number problem requires generating all possible letter combinations that a given digit string could represent based on the mapping of digits to letters on a telephone keypad. Each digit from 2 to 9 maps to a set of letters.
The task is to return all possible letter combinations that can be formed by choosing one letter for each digit in the same order.
Digit to letter mapping follows the standard phone keypad:
2 ? "abc"
3 ? "def"
4 ? "ghi"
5 ? "jkl"
6 ? "mno"
7 ? "pqrs"
8 ? "tuv"
9 ? "wxyz"
Example 1
Input: digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Explanation: Digit '2' maps to "abc" and digit '3' maps to "def". All possible combinations are formed by pairing each letter of "abc" with each letter of "def".
Example 2
Input: digits = ""
Output: []
Explanation: Since no digits are provided, no letter combinations can be formed.
Example 3
Input: digits = "7"
Output: ["p","q","r","s"]
Explanation: Digit '7' maps to "pqrs", so each letter itself forms a valid combination.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
23
ad ae af bd be bf cd ce cf
2
a b c
7
p q r s