Easy · Strings

Minimum Add to Make Parentheses Valid

Given a string s of only '(' and ')', return the minimum number of parentheses that must be inserted (at any positions) to make s a valid parentheses string.

Examples

Example 1

{
  "s": "())"
}

Output: 1 to add

Example 2

{
  "s": "((("
}

Output: 3 to add

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems