Given two strings str1 and str2 each of length N, the task is to generate and print all possible strings of length N such that the character at index i of the generated string is either str1[i] or str2[i]
Input: str1 = “abc”, str2 = “def”
Input: str1 = “a”, str2 = “b”
Approach: The problem can be solved using recursion and at each recursive call, we need to select either the character at str1[i] or the character at str2[i] and append it to the resultant string. The termination condition will be when the length of the resultant string becomes equal to the length of the given strings.
Below is the implementation of the above approach:
abc abf aec aef dbc dbf dec def
- Generate all binary strings from given pattern
- Generate all binary strings without consecutive 1's
- Generate all the binary strings of N bits
- Generate Binary Strings of length N using Branch and Bound
- Generate all binary strings of length n with sub-string "01" appearing exactly twice
- Generate two output strings depending upon occurrence of character in input string.
- Generate two output strings depending upon occurrence of character in input string in Python
- Find the Mid-Alphabet for each index of the given Pair of Strings
- Meta Strings (Check if two strings can become same after a swap in one string)
- Search in an array of strings where non-empty strings are sorted
- Count of strings that become equal to one of the two strings after one removal
- Pairs of complete strings in two sets of strings
- Number of common base strings for two strings
- Distinct strings such that they contains given strings as sub-sequences
- Generate n-bit Gray Codes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.