This question has been asked in interviews of many giant tech companies. The statement is:
Given a string in the form of numbers on a keypad of a mobile phone, print all the combinations of alphabets that are possible if the numbers are typed on a phone. Assume that the numbers 0 and 1 are not typed.
e.g.
input = 3
output = {d, e, f}
input = 24
output = {ag, bg, cg, ah, bh, ch, ai, bi, ci}
The algorithm I used is a simple recursive one in which the characters are chosen according to the input alphabet and the current character being observed as shown below:
Given a string in the form of numbers on a keypad of a mobile phone, print all the combinations of alphabets that are possible if the numbers are typed on a phone. Assume that the numbers 0 and 1 are not typed.
e.g.
input = 3
output = {d, e, f}
input = 24
output = {ag, bg, cg, ah, bh, ch, ai, bi, ci}
The algorithm I used is a simple recursive one in which the characters are chosen according to the input alphabet and the current character being observed as shown below: