Binary Replacement
Last updated
Was this helpful?
Last updated
Was this helpful?
Write a program that takes in a binary string that also contains x's and prints out all possible binary strings where each x can be replaced with either a 0 or 1.
Example
The Idea: Iterate through the string: when there is an x, append both 0 and 1 to the string, and branch out on each one of these cases. Otherwise just branch by 1.
Complexity: O(2^n + |S| - n) where n is the number of 'x's, and S is the length of the string.
Recursive Approach