

You are given ‘expr’ = “(a+b)+((c+d))”, here the subexpression “c+d” is surrounded by two parentheses. Hence the expression contains duplicate parenthesis. Hence the answer is “YES”.
The first line of input contains a single integer ‘T’, representing the number of test cases.
The first line of each test case contains a string, ‘expr’, representing the given expression.
For each test case, print “YES” if the expression contains a duplicate parenthesis. Otherwise, print “NO”.
Print a single line for each test case.
1 <= T <= 10
1 <= |expr| <= 10^6
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the function.
In this approach, we will use the stack data structure and iterate through every character in the expression of the character is not a closed parenthesis ( ( ) then, we push it to the top of the stack. Otherwise, if a closing parenthesis is found we pop the stack until a ‘(‘ is found. If the number of characters between the parenthesis is not greater than 1 then return false. Otherwise, return true.
Algorithm: