Problem Description
Given a string A of parantheses ‘(‘ or ‘)’.
The task is to find minimum number of parentheses ‘(‘ or ‘)’ (at any positions) we must add to make the resulting parentheses string valid.
An string is valid if:
1 <= |A| <= 105
A[i] = '(' or A[i] = ')'
First and only argument is an string A.
Return a single integer denoting the minimumnumber of parentheses ‘(‘ or ‘)’ (at any positions) we must add in A to make the resulting parentheses string valid.
Input 1:
A = "())"
Input 2:
A = "((("
Output 1:
1
Output 2:
3
Explanation 1:
One '(' is required at beginning.
Explanation 2:
Three ')' is required at end.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.