Skip to content
Decoder

Phone Keypad Letter Combinations

Medium

Problem

On an old phone keypad, each digit from 2 to 9 maps to letters:

Example 1

2: abc   3: def   4: ghi   5: jkl

Example 2

6: mno   7: pqrs  8: tuv   9: wxyz

Given a string digits made of the characters 2 to 9, return every string that could be typed by picking one letter per digit, in order. Return them in any order. An empty input gives an empty list.

Example 3

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

Example 4

Input
"2"
Output
["a", "b", "c"]

Example 5

Input
""
Output
[]

Constraints

  • 0 <= digits.length <= 4
  • digits[i] is a digit from '2' to '9'.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.