Phone keypad combinations
Return all letter combinations for a digit string containing only 2 through 9, in lexicographic order. Empty input returns [].
prefixes = ['a', 'b']
letters = 'de'
print([prefix+char for prefix in prefixes for char in letters])Reason about the state
Extend every existing prefix with each letter assigned to the next digit. The output size is exponential, so runtime should scale with emitted combinations. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return all letter combinations for a digit string containing only 2 through 9, in lexicographic order. Empty input returns [].
The explanation opens here once every check passes.