Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Letter Combinations of Phone Number

Medium Acceptance 60.00% Points 30.00

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"

Examples
Example 1

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

Example 2

Input: digits = ""

Output: []

Explanation: Since no digits are provided, no letter combinations can be formed.

Example 3

Example 3

Input: digits = "7"

Output: ["p","q","r","s"]

Explanation: Digit '7' maps to "pqrs", so each letter itself forms a valid combination.

Hints
Hint 1
N/A
Constraints
  • 0 = digits.length = 4
  • digits[i] is a digit from '2' to '9'
Companies
Amazon Microsoft
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions