Facebook | Onsite | Variant of phone letters combination

Hello,

I interviewed with Facebook two weeks ago. They asked variation of the combination of telephone letter.
Again, the mapping is given. Input is the combination of digits. Output is the combination of input. However, if there is consequtive duplicate numbers such as [1,1], the combination is ['AA' or 'B'].

mapping = {1 -> ['A', 'B', 'C'],
2 -> ['D', 'E', 'F'],
3 -> ['G', 'H', 'I'],
4 -> ['J', 'K', 'L'],
5 -> ['M', 'N', 'O'],
6 -> ['P', 'Q', 'R'],
7 -> ['S', 'T'],
8 -> ['U', 'V', 'W'],
9 -> ['X', 'Y'],
0 -> ['Z']}

E.g. 1: Input: [1, 1, 2] Output: ["AAD" , "BD"]
E.g. 2: Input: [1, 1, 1, 2] Output: ["AAAD", "ABD", "CD", "BAD"]

Comments (4)