Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. 2: abc, 3: def, 4: ghi, 5: jkl, 6: mno, 7: pqrs, 8: tuv, 9: wxyz.
Example 1
Input: digits = 23
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Explanation: Digit 2 maps to a, b and c, and digit 3 maps to d, e and f. Pairing each letter of the first with each letter of the second gives 3 × 3 = 9 combinations.
Example 2
Input: digits = 2
Output: ["a","b","c"]
Explanation: Digit 2 maps to a, b and c, so there are three one-letter combinations.
Example 3
Input: digits = 9
Output: ["w","x","y","z"]
Explanation: Digit 9 maps to w, x, y and z, so there are four one-letter combinations.
Each digit contributes one letter to the combination. Recurse position by position: for the current digit, try each of its letters, append it, recurse to the next digit, then undo. When all digits are placed, the built string is one combination.
Run checks all cases above. Submit evaluates all test cases.