Letter Combinations of a Phone Number
Given a nonempty string digits containing only digits 2 through 9, return every letter combination that those digits could represent on a telephone keypad.…
Given a nonempty string digits containing only digits 2 through 9, return every letter combination that those digits could represent on a telephone keypad. Use exactly one mapped letter for each digit, in the same positional order. Return each combination exactly once, in any order. The mapping is 2: abc, 3: def, 4: ghi, 5: jkl, 6: mno, 7: pqrs, 8: tuv, 9: wxyz.
- 1 <= digits.length <= 4. - Every character is an ASCII digit from '2' through '9'. - Each output string has digits.length letters and respects the mapping at every position. - Repeated digits are allowed; output order does not matter.
Example 1: input digits = "34"; output ["dg","dh","di","eg","eh","ei","fg","fh","fi"]. Choose one of d, e, f for the first position and one of g, h, i for the second.
Example 2: input digits = "3"; output ["d","e","f"]. A single key returns its three mapped letters.
Example 3: input digits = "22"; output ["aa","ab","ac","ba","bb","bc","ca","cb","cc"]. Positions are separate choices. Both ab and ba are valid and distinct.
Category: Recursion. Topic: recursion. Difficulty: Hard. Patterns: backtracking.