Generate Binary Strings from Pattern
Given a string STR
containing '0', '1', and '?' special characters, generate all possible strings by replacing each '?' with either '0' or '1'.
Input:
The first line contains an integer 'T' representing the number of test cases.
Each of the following T lines contains a string 'STR' consisting of characters '0', '1', and '?'.
Output:
For each test case, return all possible strings in lexicographically sorted order that can be generated as described.
Example:
Input:
2
1?0?
??
Output:
["1000", "1001", "1100", "1101"]
["00", "01", "10", "11"]
Constraints:
- 1 <= T <= 50
- 1 <= |STR| <= 30
Note:
The number of special characters '?' will not exceed 14.
AnswerBot
2d
Generate all possible binary strings by replacing '?' with '0' or '1'.
Iterate through the input string and replace '?' with '0' and '1' recursively to generate all possible strings.
Use backtracking to...read more
Help your peers!
Add answer anonymously...
Top Microsoft Corporation Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Microsoft Corporation Software Developer
>
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app