Equal point in a string of brackets
Submissions: 4065   Accuracy:

30.66%

  Difficulty: Easy   Marks: 2

Given a string S of opening and closing brackets '(' and ')' only. The task is to find an equal point. An equal point is an index such that the number of closing brackets on right from that point must be equal to number of opening brackets before that point.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an string S.

Output:
For each test case in a new line print the occurrence of the first equal point in the array.

Constraints:
1 <= T <= 100
1 <= S <= 106
Example:
Input:

2
(())))(
))

Output:
4
2

Explanation:
Testcase 1:
After index 4 (0-based indexing), number of closing on right from 4th index is 2 and closing before 4th is 2.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.