Given a number as a string where some of the digits are replaced by a ‘$’, the task is to generate all possible number by replacing the ‘$’ with any of the digits from the given string.
Input: str = “23$$”
Input: str = “$45”
- Find all the combinations of the string by replacing the character $ with any of the digits of the string, for this check if the current character is a digit if yes then store this character into an array pre then recursively find all of its combinations else if current character is a ‘$’ then replace it with the digits stored in the array and recursively find all the combinations.
- To find the all possible numbers initialize array set that stores all the possible numbers, to generate numbers take two nested loop outer loop is for input string and inner loop is for array set that stores all the possible combinations of the numbers. Initialize the boolean flag to check if character of the input string is already present in set or not if character of the input string is already present in set then set flag = false else if flag is true then move the current character of the input string to set and recursively find all the combinations of the input string and store it in the array set. Finally print each number from the array set
Below is the implementation of the above approach:
2322 2323 2332 2333
- Print all the combinations of a string in lexicographical order
- Check if a string can be converted to another string by replacing vowels and consonants
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Find the resultant String after replacing X with Y and removing Z
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Make the string lexicographically smallest and non palindromic by replacing exactly one character
- Count of integers obtained by replacing ? in the given string that give remainder 5 when divided by 13
- Print the longest prefix of the given string which is also the suffix of the same string
- Print substring of a given string without using any string function and loop in C
- Print string after removing all (“10” or “01”) from the binary string
- Print shortest path to print a string on screen
- Split the given string into Odds: Digit DP
- Split the given string into Primes : Digit DP
- Find the most frequent digit without using array/string
- Append a digit in the end to make the number equal to the length of the remaining string
- Print all possible combinations of words from Dictionary using Trie
- Print all subsequences of a string
- Print string of odd length in 'X' format
- Print all the duplicates in the input string
- Given a string, print all possible palindromic partitions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.