Question: Given a string (for example: "a?bc?def?g"), write a program to generate all the possible strings by replacing ? with 0 and 1.
Example:
Input : a?b?c?
Output: a0b0c0, a0b0c1, a0b1c0, a0b1c1, a1b0c0, a1b0c1, a1b1c0, a1b1c1.
Algorithm:
1. Count the number of '?'s in the string.
2. Initialize a char [] of that size.
3. Insert the possible sequences of 0s and 1s in the array.
4. Everytime when the array is filled, replace ?s in the string with the contents of the filled array.
Read full article from codebytes: Coding Interview Question : Given a string (for example: "a?bc?def?g"), write a program to generate all the possible strings by replacing ? with 0 and 1.