Remove Invalid Parentheses

Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.

Return a list of unique strings that are valid with the minimum number of removals. You may return the answer in any order.

Example 1
Inputs = "()())()"
Output["(())()","()()()"]
Removing one invalid closing parenthesis can produce either (())() or ()()(), and both are valid with the minimum number of removals.
Example 2
Inputs = "(a)())()"
Output["(a())()","(a)()()"]
Removing one invalid closing parenthesis can produce either (a())() or (a)()(), and both are valid with the minimum number of removals.

Constraints

  • 1 <= s.length <= 25
  • s consists of lowercase English letters and parentheses '(' and ')'.
  • There will be at most 20 parentheses in s.

Asked at 10 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate