mediumBacktrackingPure DSA~25 min
Keypad Letter Combinations
An old-style numeric keypad maps each digit 2–9 to a set of letters. Given a typed digit sequence, enumerate every letter combination it could represent — the core of a T9-style suggestion box.
Problem
Given a string digits containing digits from 2-9, return all possible letter combinations the number could represent. Return the answer in any order. An empty input yields an empty list.
Input
A string digits of length [0, 4], each character in '2'..'9'.
Output
A list of strings: all letter combinations.
Constraints
- 0 <= digits.length <= 4
- digits[i] is in the range ['2', '9'].
Examples
Example 1
Input
digits = "23"
Output
["ad","ae","af","bd","be","bf","cd","ce","cf"]
2→abc, 3→def; cartesian product.
Example 2
Input
digits = ""
Output
[]
No digits, no combinations.