Medium · Strings

Minimum Remove to Make Valid Parentheses

Given a string s of lowercase letters, '(' and ')', remove the minimum number of parentheses so that the result is a valid parentheses string, and return any such result.

Examples

Example 1

{
  "s": "a)b(c)d"
}

Output: "ab(c)d"

Example 2

{
  "s": "lee(t(c)o)"
}

Output: "lee(t(c)o)"

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems