All combinations of strings that can be used to dial a number
Given a number, print all possible combinations of strings that can be used to dial the given number in a phone with following specifications.
In the given phone, we can dial,
2 using A or B or C,
3 using D or E or F,
8 using T or U or V,
9 using W or X or Y or Z,
1 using only 1
0 using 0.
For example if 23, is the given phone number, the program should print AD, AE, AF, BD, BE, BF, CD, CE, CF
The idea is to store digit to characters mapping in hash map. The map stores all characters that can be used dial a digit. We place every possible character for current digit and recur for remaining digits. Below is Java implementation of this idea.
AD AE AF BD BE BF CD CE CF
This article is contributed by Phalgun. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above