Letter Combinations of a Phone Number

Medium

Question

You are given a string of digits from 2-9 (inclusive), where each digit is mapped to letters based on this phone keypad layout:

Meeting Rooms I Example 1

Generate all unique combinations of letters that can be formed by pressing these digits on the keypad.

Input: digits = "65"

Output: ["mj", "mk", "ml", "nj", "nk", "nl", "oj", "ok", "ol"]

4 can represent "m", "n", or "o" while 5 can represent "j", "k", or "l".

Input: digits = "9"

Output: ["w", "x", "y", "z"]

4 can represent "w", "x", "y", "z".

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

How many unique combinations are there when digits = "59"?
5
7
9
12
# You are given a string of digits from 2-9 (inclusive), where
# each digit is mapped to letters based on the above phone keypad layout.
#
# Generate all unique combinations of letters that can be
# formed by pressing these digits on the keypad.
#
# Input: digits = "65"
# Output: ["gj", "gk", "gl", "hj", "hk", "hl", "ij", "ik", "il"]

class Solution:
# You may reuse this dictionary to map digits to letters.
MAPPING = {
"2" : "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz"
}

def combinations(self, digits: str) -> List[str]:

Login or signup to save your code.

Notes

Saving...