01 · Question
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.
02 · Analysis
One recursion level chooses a letter for the next input digit. Save a copy or joined string only after every digit has a choice; restore the path after each branch. For n digits there are at most 4^n outputs, so time and output space are O(n*4^n), with O(n) auxiliary path/stack space. Empty input returns an empty result for this problem, not a list containing an empty string.