Letter Combinations - Implementation

Here is the implementation:

function letterCombinations(digits):
    if digits is empty:
        return []

    mapping = {
        '2': "abc", '3': "def", '4': "ghi", '5': "jkl",
        '6': "mno", '7': "pqrs", '8': "tuv", '9': "wxyz"
    }
    result = []
    backtrack(0, "")
    return result

function backtrack(index, current):
    if index == digits.length:
        result.append(current)
        return

    for letter in mapping[digits[index]]:
        backtrack(index + 1, current + letter)

O(4n)O(4^n) time in worst case (digits 7 and 9 have 4 letters). O(n)O(n) space for recursion.