**Problem: **Find the place where the bracket doesn’t ends properly or the chain breaks.

**Input Format**: First line contains a single integer, the number of testcases n. Next n line contains a string consists of brackets.

*(***NOTE**: The actual problem didn’t have the number of testcases as input. But for your better convenience we have worked with testcases.)

**NOTE**: The actual problem didn’t have the number of testcases as input. But for your better convenience we have worked with testcases.)

**Sample Input:**

```
3
())
[][][
{{[]}}}
```

**Sample Output:**

```
3
6
7
```

**Explanation**: In the first input “())” third index the bracket closes but it doesn’t have any opening bracket (the chain breaks), the first bracket in position 1 is closed in the second position, Hence the output should be 3.

In the second example “[][][“, bracket in the 5th position opens but doesn’t close anywhere. Hence it returned the position where it should have closed (position of chain break) i.e. 6.

In the last example, the closing bracket in the 7th position is extra. It closes but doesn’t have any opening bracket of it (breaking of the chain). Hence it returned 7.

**Solution:** We strongly recommend you to try the problem first before moving to the solution.

```
# Solution of Bracket Validator problem in Python
# www.codewindow.in
def validator(str): # Function validator to check
st=[]
count=0
for a in str:
if a=='[' or a=='{' or a=='(':
st.append(a)
count+=1
continue
if len(st)==0:
return count+1
x=st.pop()
if a==']' and x=='[':
count+=1
elif a=='}' and x=='{':
count+=1
elif a==')' and x=='(':
count+=1
else:
return count+1
if len(st)==0:
return 0
else:
return count+1
# Driver Code
test_case=int(input()); # Take number of testcases
while(test_case):
str=input()
print(validator(str))
test_case-=1
```

**Input:**

```
3
())
[][][
{{[]}}}
```

**Output:**

```
3
6
7
```

**Follow Us**

**You Missed**

- Juspay Hiring Challenge | Think big with Functional Programming | Codewindow.in
- Exam Answers
- IBM Off Campus Hiring | Associate System Engineer | Codewindow.in
- FindMax Problem
- Walmart Off Campus Hiring | Walmart CodeHers | Codewindow.in
- Quadratic Equation Solution | Codewindow.in
- Accenture Solution | Code in Marathon | Codewindow.in
- Amazon Off Campus Internship Drive | Amazon WoW for the batch of 2022, 2023, and 2024 | Codewindow.in
- Binary Tree Combination
- Sum of all the prime divisors of a number
- Mindtree Interview Questions and Experience Part 1 | Codewindow.in
- Apisero Off Campus Recruitment Drive | Software Engineer | 2021 2020 2019 2018 | Codewindow.in
- Infosys Mega Off Campus HIring | Technincal Process Executive | Codewindow.in
- Amazon Off Campus Hiring | Software Development Engineer | 2021/2020/2019/2018 | Codewindow.in
- Question 3 Solution | Duplicate Elements Solution | Codewindow.in
- Question 2 Solution | Second Largest Solution | Codewindow.in
- Question 1 Solution | Palindrome Solution | Codewindow.in
- Question 2 Coding Solution | Weak String Problem | Codewindow.in
- Question 1 Coding Solution | Permutation Problem | Codewindow.in
- XL Dynamics Off Campus Hiring | 2022 2021 2020 | Codewindow.in
- Accenture Full Question Paper Set | Codewindow.in
- Accenture Aptitude Questions and Solution | Codewindow.in
- Accenture Logical Reasoning Questions and Solution | Codewindow.in
- MountBlue Solution | PlayGame Code | Codewindow.in
- MountBlue Solution | !On Off Code | Codewindow.in
- Revature Answer | 2021
- IBM Mixed Fraction Code Solution | CodeWindow.in
- IBM Volume of Pizza Slice Solution | CodeWindow.in
- Accenture Running Distance Code Solution
- Accenture Pizza Code Solution
- Cognizant GENC Off-Campus | 2021 | CodeWindow.in
- Revature Coding Solution with proof | Array Operation: Ascending order | Codewindow.in