dsa · medium
Letter Combinations of a Phone Number
A phone keypad maps digits to letters:
Arguments
digits— string of keypad digits 2-9; empty means no combinations
- 2 ABC, 3 DEF, 4 GHI, 5 JKL, 6 MNO, 7 PQRS, 8 TUV, 9 WXYZ
Given a string digits of digits 2-9, return every letter combination those digits could represent, in any order. Return [] if digits is empty.
Example
"23" → ["ad","ae","af","bd","be","bf","cd","ce","cf"].
"" → [].
"2" → ["a","b","c"].
Constraints
0 <= digits.length <= 4 digits[i] is a digit in the range ["2", "9"]
Examples
Example 1
Input: "23" Expected: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2
Input: "" Expected: []
Example 3
Input: "2" Expected: ["a","b","c"]