Evaluating a string expression 2


Given a string containing digits from 0-9, using the corresponding alphabet on the telephone pad, return all possible letter combinations that the number could represent. Note, that 0 and 1 do not map to any letters.
For example, if you're given [2, 3, 4], your function should return 27 3-letter combinations:

['a', 'd', 'g']
['a', 'd', 'h']
['a', 'd', 'i']
['a', 'e', 'g']
['a', 'e', 'h']
['a', 'e', 'i']
['a', 'f', 'g']
['a', 'f', 'h']
['a', 'f', 'i']
['b', 'd', 'g']
['b', 'd', 'h']
['b', 'd', 'i']
['b', 'e', 'g']
['b', 'e', 'h']
['b', 'e', 'i']
['b', 'f', 'g']
['b', 'f', 'h']
['b', 'f', 'i']
['c', 'd', 'g']
['c', 'd', 'h']
['c', 'd', 'i']
['c', 'e', 'g']
['c', 'e', 'h']
['c', 'e', 'i']
['c', 'f', 'g']
['c', 'f', 'h']
['c', 'f', 'i']


Access restricted

Subscribe to premium account to see the solution.

Get premium now