Consider below list where each digit from 1 to 9 maps to few characters.
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', 'U'] 8 -> ['V', 'W', 'X'] 9 -> ['Y', 'Z']
Given a number, replace its digits with corresponding characters in given list and print all strings possible. Same character should be considered for every occurrence of a digit in the number. Input number is positive and doesn’t contain 0.
Input : 121 Output : ADA BDB CDC AEA BEB CEC AFA BFB CFC Input : 22 Output : DD EE FF
The idea is for each digit in the input number, we consider strings formed by previous digit and append characters mapped to current digit to them. If this is not the first occurrence of the digit, we append same character as used in its first occurrence.
ADA BDB CDC AEA BEB CEC AFA BFB CFC
This article is contributed by Aditya Goel. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. 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
- Find maximum number that can be formed using digits of a given number
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Greatest number less than equal to B that can be formed from the digits of A
- Find the numbers of strings that can be formed after processing Q queries
- Recursive sum of digits of a number formed by repeated appends
- Find uncommon characters of the two strings
- Find uncommon characters of the two strings | Set 2
- Find the count of sub-strings whose characters can be rearranged to form the given word
- Remove minimum number of characters so that two strings become anagram
- Number of ways in which the substring in range [L, R] can be formed using characters out of the range
- Least number of manipulations needed to ensure two strings have identical characters
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- K length words that can be formed from given characters without repetition
- Lexicographically largest string formed from the characters in range L and R