Phone-Number Letter Combinations
Problem statement
Given a string digits, return every letter combination represented by its digits on a telephone keypad.
For this exercise, assume the standard mapping:
2maps toabc.3maps todef.4maps toghi.5maps tojkl.6maps tomno.7maps topqrs.8maps totuv.9maps towxyz.
Choose exactly one mapped letter for each digit, preserving the digit positions. Return all combinations in ascending lexicographic order. For this exercise, assume an empty digits string returns an empty array, not an array containing an empty string.
Function
letterCombinations(digits: String) → String[]Examples
Example 1
digits = "23"return = ["ad","ae","af","bd","be","bf","cd","ce","cf"]Choose one letter from abc, then one from def. Listing the choices in ascending order gives nine combinations.
Example 2
digits = ""return = []The empty-input rule returns no combinations.
Example 3
digits = "79"return = ["pw","px","py","pz","qw","qx","qy","qz","rw","rx","ry","rz","sw","sx","sy","sz"]Both digits have four letters. Each letter from pqrs is paired with every letter from wxyz, producing sixteen ordered combinations.
Constraints
0 <= digits.length <= 4.- Every character in
digitsis a digit from2through9.