How to approach this problem??
Redundant Parentheses Problem
@ashwani225
The idea is to use stack.
For any sub-expression of expression, if we able to pick any sub-expression of expression surrounded by (), then we again left with () as part of string, we have redundant braces.
We iterate through the given expression and for each character in the expression, if the character is a open parenthesis β(β or any of the operators or operands, we push it to the stack. If the character is close parenthesis β)β, then pop characters from the stack till matching open parenthesis β(β is found.
Now for redundancy two condition will arise while popping-
- If immediate pop hits a open parenthesis β(β, then we have found a duplicate parenthesis. For example, (((a+b))+c) has duplicate brackets around a+b . When we reach second β)β after a+b, we have β (( β in the stack. Since the top of stack is a opening bracket, we conclude that there are duplicate brackets.
- If immediate pop doesnβt hit any operand(β*β, β+β, β/β, β-β) then it indicates the presence of unwanted brackets surrounded by expression. For instance, (a)+b contain unwanted () around a thus it is redundant.
dont forget to hit like and mark resolved if cleared 
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.