Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Phone Keypad Combinations

On an old phone keypad, each digit from 2 to 9 maps to a set of letters, just like on classic telephone keypads:

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

Given a string digits containing only characters from 2 through 9, return all possible letter combinations that the number could represent, in any order. If digits is empty, return an empty list.

Example 1:

Input:  digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]

Example 2:

Input:  digits = ""
Output: []

Example 3:

Input:  digits = "2"
Output: ["a","b","c"]

Constraints:

  • 0 <= digits.length <= 4
  • digits[i] is a digit in the range ['2', '9'].

Share this question

← Back to Backtracking practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.