Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given the expression ‘expr’ with parenthesis. Your task is to find if the given expression contains duplicate parenthesis. A set of parenthesis is duplicate if multiple parenthesis surrounds the same subexpression.

```
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”.
```

Detailed explanation

```
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.
```

```
2
(a+b)+((c+d))
((a+b) + c)
```

```
YES
NO
```

```
For the first test case, ‘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”.
For the second test case, ‘expr’ = “((a+b) + c)”, here, no subexpression is surrounded by multiple parentheses. Hence the answer is “NO”.
```

```
2
(a+b)+((c+d))
((a+b)+(c+d))
```

```
YES
NO
```