Practice/ServiceNow/Leetcode 17. Letter Combinations of a Phone Number
CodingMust
On a classic telephone keypad, each digit from 2 through 9 is associated with a set of letters. Your task is to generate all possible letter combinations that can be formed by pressing a sequence of these digits.
Given a string containing digits from 2 to 9 inclusive, return all possible letter combinations that the number could represent in any order.
The digit-to-letter mapping follows the standard phone keypad layout:
digits is a digit in the range ['2', '9']Example 1:
Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] Explanation: The combinations are formed by taking one letter from digit 2 (a, b, or c) and one letter from digit 3 (d, e, or f).
Example 2:
Input: digits = "" Output: [] Explanation: No digits means no combinations to generate.
Example 3:
Input: digits = "2" Output: ["a","b","c"] Explanation: Digit 2 corresponds to three letters on the keypad.
Example 4:
Input: digits = "79" Output: ["pw","px","py","pz","qw","qx","qy","qz","rw","rx","ry","rz","sw","sx","sy","sz"] Explanation: Digits 7 and 9 each map to 4 letters, creating 16 total combinations.