Skip to contentKEEP THE CRAFTTHE SANCTUARY

Phone Keypad Letter Combinations

List every letter string a sequence of phone keypad digits can spell.

The problem

Implement Solution.letterCombinations(digits). Each digit from 2 to 9 stands for the letters on a phone keypad: 2 = abc, 3 = def, 4 = ghi, 5 = jkl, 6 = mno, 7 = pqrs, 8 = tuv, 9 = wxyz. Return every string you can make by picking one letter for each digit, in order. For example, "23" gives ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. If digits is empty, return []. The result can be in any order. digits has at most 4 characters, each from 2 to 9.

Starter code

class Solution:
    def letterCombinations(self, digits: str) -> list[str]:
        pass

Public examples

  1. digits = "23"gives["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
  2. digits = "8"gives["t", "u", "v"]
  3. digits = "79"gives["pw", "px", "py", "pz", "qw", "qx", "qy", "qz", "rw", "rx", "ry", "rz", "sw", "sx", "sy", "sz"]

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.