Minimum Add To Make Parentheses Valid

medium
1: Given a string S of '(' and ')' parentheses.
2: You need to find count of minimum number of parentheses '(' or ')' when added in any positions so that the resulting parentheses string is valid.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1: S.length <= 1000
2: S only consists of '(' and ')' characters.

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
()))((
Output
4
Previous
Design A Stack With Increment Operation
Next
Score Of Parentheses

Related Questions