Minimum Add to Make Parentheses Valid
s has only ( and ). You may insert parentheses anywhere. Return the fewest insertions that make s a valid parentheses string, where every ( is closed in order by a later ) and every ) closes an earlier (.
Example 1
s "())"
returns 1
Add one ( at the front.
Example 2
s "((("
returns 3
Three ) are needed.
Constraints
0 <= len(s) <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.