s contains only ( and ) and may be unbalanced. You may insert parentheses anywhere. Return the minimum number of insertions needed to make s a valid balanced string, where every ( has a matching ) after it.
Example 1
Input:
min_add_to_make_valid('())')
Output:
1
Insert one ( at the start.
Example 2
Input:
min_add_to_make_valid('(((')
Output:
3
Insert three ).
0 <= len(s) <= 3 * 10**5s contains only ( and ).No results yet
Run your code to check it against the examples, or submit to run every test.