
Asked in MAQ Software
Remove Invalid Parentheses
Given a string containing only parentheses and letters, your goal is to remove the minimum number of invalid parentheses to make the input string valid and return all possible valid strings.
Input:
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single string ‘STR’ representing the parentheses and letters.
Output:
For each test case, return all possible unique valid strings obtained after removing the minimum number of parentheses. Each test case output should be printed in a separate line.
Example:
Input:
T = 2
STR = "()())()"
STR = "(a)())()"
Output:
["()()()", "(())()"]
["(a)()()", "(a())()"]
Constraints:
- 1 <= T <= 5
- 1 <= |STR| <= 50
- Time Limit: 1 second
Note:
A string is valid if every left parenthesis has a corresponding right parenthesis in the same order. Example: 'STR' = "(())())" is not valid, but 'STR' = "(())()" is valid.

AnswerBot
4mo
Given a string with parentheses and letters, remove minimum invalid parentheses to make it valid and return all possible valid strings.
Use BFS to explore all possible valid strings by removing parenth...read more
Help your peers!
Add answer anonymously...
Top Software Engineer Interview Questions Asked at MAQ Software
Q. How does hashing help in identifying duplicate values?
Q. What is the difference between span and div tags?
Q. Given an array and a number, determine whether the number can be generated using...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for MAQ Software Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 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

