Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Minimum Parentheses Removal (Main Thread)

Here is the interview question prompt, presented for reference.

A string that contains correctly ordered parenthesis (), is a valid parenthesis string. More specifically, it must meet the following conditions:

  • It is an empty string or contains only lowercase characters.
  • It can be written as AB (A concatenated with B), where A and B are valid strings.
  • It can be written as (A), where A is a valid string.

Given a string s, consisting of parenthesis and lowercase English characters. Remove the minimum number of parentheses ( '(' or ')' ) to make the resulting parentheses string valid. Multiple valid strings may be possible, but since minimum removal operations are performed, there will be only one correct answer.

![image](https://storage.googleapis.com/algodailyrandomassets/curriculum/easy-strings/minimum-parentheses-removal/problem.png)

For example, consider the following string as input:

s = "alg(o(d)a)il)y"

All parenthesis are valid except the last one. Removing it will give alg(o(d)a)ily which is the correct answer. alg(o(da)il)y or alg(o(d)ail)y could also be correct answers, but they require more operations, and hence only alg(o(d)a)ily is valid.

Note: this problem is similar to Remove Invalid Parentheses, with the difference being that we only want the smallest valid result.

Constraints

  • 1 <= s.length <= 105
  • s[i] is either'(' , ')', or lowercase English letter.

You can see the full challenge with visuals at this link.

Challenges • Asked over 1 year ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Aug 28, 2022:

This is the main discussion thread generated for Minimum Parentheses Removal (Main Thread).