Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Solution: Letter Combinations of a Phone Number

Problem Statement

Given a string digits containing digits from 2-9, return an array of strings containing all possible letter combinations that the number could represent. You may return the answer in any order.

The mapping of digits to letters (just like on the telephone buttons) is as given below.

  • 1 -> It doesn't map any number.
  • 2 -> "abc"
  • 3 -> "def"
  • 4 -> "ghi"
  • 5 -> "jkl"
  • 6 -> "mno"
  • 7 -> "pqrs"
  • 8 -> "tuv"
  • 9 -> "wxyz"

Examples

  • Example 1:
    • Input: digits = "47"
    • Expected Output:

.....

.....

.....

Like the course? Get enrolled and start learning!