Letter Combinations of a Phone Number — JavaScript Coding Problem
Difficulty: medium | Category: backtracking
Problem Description
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in lexicographic order. Phone key mapping: 2→abc, 3→def, 4→ghi, 5→jkl, 6→mno, 7→pqrs, 8→tuv, 9→wxyz. Hint: Use backtracking — at each position, iterate over the letters for the current digit and recurse for the remaining digits.
Examples
Example 1
Input: digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Explanation: 2→abc, 3→def
Example 2
Input: digits = ""
Output: []
Example 3
Input: digits = "2"
Output: ["a","b","c"]