Last Updated: 11 Dec, 2020
##### Redundant Brackets
Easy
Problem statement

#### A pair of brackets is said to be redundant when a subexpression is surrounded by needless/ useless brackets.

##### For Example :
``````((a+b)) has a pair of redundant brackets. The pair of brackets on the first and last index is needless.
While (a + (b*c)) does not have any pair of redundant brackets.
``````
##### Input Format :
``````The first line contains a single integer βTβ denoting the number of test cases. The test cases follow.

The first line of each test case contains a string denoting the expression.
``````
##### Output Format :
``````For each test case, return βYesβ if the given expression contains at least one pair of redundant brackets, else return βNoβ.
``````
##### Note :
``````You donβt need to print anything; It has already been taken care of. Just implement the given function.
``````
##### Constraints :
``````1 <= T <= 50
3 <= |S| <= 10^4

Time Limit: 1 sec
``````
Approaches

## 01Approach

The idea is to use the stack to keep track of the opening and closing brackets. If we remove any subexpression from the given string which is enclosed by β()β and after that, if there exist any pair of opening and closing bracketsβ()β which does not have any operator(β+β,β-β,β*β,β/β) in between them, then the expression will have a redundant pair of brackets.

The steps are as follows :

1. Define a stack, for keeping track of pairs of opening and closing brackets, letβs say βBRACKETSβ.
2. Iterate through the string and whenever we encounter an opening bracket or an operator( { β(β, β+β, β-β, β*β, β/β, } ) we will push the current character to the stack(βBRACKETSβ).
3. Whenever we encounter β)β in the string
1. Now we will pop characters from the stack(βBRACKETSβ) until we pop an opening bracket { β(β }  from the stack.
2. If we find any operator ( { β+β, β-β, β*β, β/β } )  before encountering β(β then the current bracket is not redundant.
3. If we do not find any operator, then the current bracket is redundant. Hence we will return true.
4. If there is no redundant bracket, then return false.