Remove Invalid Parentheses

Given a string A consisting of lowercase English alphabets and parentheses ’(‘ and ’).
Remove the minimum number of invalid parentheses in order to make the input string valid.

Return all possible results.

You can return the results in any order.


Input Format

The only argument given is string A.

Output Format

Return all possible strings after removing the minimum number of invalid parentheses.

Constraints

1 <= length of the string <= 20

For Example

Input 1:
    A = ""()())()"
Output 1:
     ["()()()", "(())()"]
     Explanation 1:
        By removing 1 parentheses we can make the string valid.
                1. Remove the parentheses at index 4 then string becomes : "()()()"
                2. Remove the parentheses at index 2 then string becomes : "(())()"
                
        

Input 2:
    A = "(a)())()"
Output 2:
    ["(a)()()", "(a())()"]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Remove Invalid Parentheses on Interview Code Editor
Sign Up
to access hints and editorial solutions for Remove Invalid Parentheses

Discussion


Loading...
Click here to start solving coding interview questions