Mark As Completed Discussion

Good evening! Here's our prompt for today.

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

Question

For example, consider the following string as input:

SNIPPET
1s = "()())()"

The correct solution should return ["(())()","()()()"], with both possibilities.

Note: this problem is similar to Minimum Parentheses Removal, with the difference being that we want to return all possible valid string results.

Constraints

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

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's our guided, illustrated walk-through.

How do I use this guide?

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.