FastPrepLetter Combinations of a Phone Number

Letter Combinations of a Phone Number

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Digits 2 through 9 map to letters as on a telephone keypad. Return every string formed by choosing one mapped letter for each input digit.

Return an empty list for an empty input, and otherwise return combinations in lexicographic keypad order.

Function

letterCombinations(digits: String) → String[]

Examples

Example 1

digits = "23"return = ["ad","ae","af","bd","be","bf","cd","ce","cf"]

Choose one of abc for 2 and one of def for 3.

Constraints

  • 0 <= digits.length <= 8
  • Every character is between 2 and 9.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] letterCombinations(String digits) {
  // Write your code here.
}
digits"23"
expected["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
Checking account…