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
4mo
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...
Microsoft Corporation Software Developer interview questions & answers
A Software Developer was asked 8mo agoQ. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ. Why do you want to join Microsoft?
Popular interview questions of Software Developer
A Software Developer was asked 8mo agoQ1. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ2. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ3. Why do you want to join Microsoft?
>
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

