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 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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Map every character of one string to another such that all occurrences are mapped to the same character
- Strings formed from given characters without any consecutive repeating characters
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Find the number of strings formed using distinct characters of a given string
- Minimum digits to be removed to make either all digits or alternating digits same
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Find maximum number that can be formed using digits of a given number
- Find smallest number formed by inverting digits of given number N
- Minimum number of operations to move all uppercase characters before all lower case characters
- Find the largest number that can be formed by changing at most K digits
- 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
- Find smallest number with given number of digits and sum of digits under given constraints
- Sum of all numbers that can be formed with permutations of n digits
- Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9
- Replace minimal number of characters to make all characters pair wise distinct
- Check if the sum of digits of number is divisible by all of its digits
- All possible strings of any length that can be formed from a given string
- Print all possible palindromic string formed using any pair of given strings
- Print all Strings from array A having all strings from array B as subsequence
Improved By : sanjeev2552