Tuesday, August 01, 2006

Cellphone - Algo

Consider a cellphone that has buttons/keys 0, 1, 2, 3... 9 on it and the same button can be used to type a set of alphabets.

For egs:
button which has number '1' on it also can be used to type = a, b, c
2 = d, e, f

Given a phone number (say - 2330493), write an algo to return all possible alphabetical combinations equivalent to the number, which are in a particular dictionary.

For egs:
I/p - 121
Possiblities can be - ada, adb, adc, aea, aeb, bdb....
If dictionary contians only - "ada", "adc" and "fuk".

O/p should be - ada and adc.

Write an algo to do this with least time complexity.

1 comment:

Perspective Inc. said...