Skip to main content
Back to problems
Leetcode
Medium
Strings
Backtracking
Recursion
Google
Letter Combinations Of A Phone Number

Generate every possible letter string that a phone keypad number sequence can represent.

Acceptance 0%
Problem Statement

Given a string of digits from 2 to 9, return all possible letter combinations that the number could represent using the standard phone keypad mapping.

Each digit maps to a set of letters:

  • 2 -> abc
  • 3 -> def
  • 4 -> ghi
  • 5 -> jkl
  • 6 -> mno
  • 7 -> pqrs
  • 8 -> tuv
  • 9 -> wxyz

Build every valid combination by choosing one letter for each digit in order. The result may be returned in any order.

If the input contains no digits, return an empty list.

Input Format

  • A string digits containing only characters from 2 to 9.
  • Length may be zero.

Output Format

  • Return a list of strings.
  • Each string is one valid letter combination formed by mapping every digit to one letter and preserving the digit order.

Constraints

  • 0 <= digits.length
  • digits[i] is in the range '2'..'9'
  • Order of returned combinations does not matter.
Examples
Sample cases returned by the problem API.

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. Combine every choice from the first digit with every choice from the second digit.

Example 2

Input

digits = ""

Output

[]

Explanation

With no digits, there are no letter combinations to generate.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.