Problem · String
Phone Keypad Letter Combinations
Learn this problemProblem statement
Given a string digits, return every letter combination that the digits could represent on a conventional telephone keypad.
2maps toabc,3todef,4toghi,5tojkl.6maps tomno,7topqrs,8totuv, and9towxyz.
For this exercise, emit combinations in depth-first order, visiting each digit's mapped letters from left to right. Return an empty list for empty input.
Function
letterCombinations(digits: String) → List<String>Examples
Example 1
digits = "23"return = ["ad","ae","af","bd","be","bf","cd","ce","cf"]Choose one of abc for the first position and one of def for the second, following left-to-right depth-first order.
Example 2
digits = ""return = []There is no position to assign, so the exercise returns an empty list.
Constraints
0 <= digits.length <= 4- Every character in
digitsis between2and9.