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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.