Phone-Number Letter Combinations
Updated
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 letter for each digit and keep the letters in the same order as the digits. Return all combinations in alphabetical order. In this exercise, an empty digits string returns an empty array, not an array containing an empty string.
Function
letterCombinations(digits: String) → List<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.
More Headway Phone Screen questions
Similar questions at other companies
- All English Decodings of Morse CodeOscar Health · PHONE SCREEN
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Letter Combinations of a Phone NumberLinkedIn · PHONE SCREENLinkedIn interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Unique String PermutationsAmazon · PHONE SCREEN
- Permutations of Unique CharactersSalesforce · PHONE SCREENSalesforce interview questions
- Count Prefix Paths in a Character GraphGoogle · PHONE SCREENGoogle interview questions
- Sorted Subsets of a StringMicrosoft · PHONE SCREENMicrosoft interview questions
- Maximum Unique Substring SplitThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions