In the given question, the sample test case provided seems to be doubtful.
The 2nd string given in the input is also a Redundant Bracket.
In the given question, the sample test case provided seems to be doubtful.
The 2nd string given in the input is also a Redundant Bracket.
Hello @NKushal no it doesnot have any reduantant bracket.
even if you see by dry run you can prove that:
but the first has reduntant brackets which you can see.
I checked the 2nd sample test case at different sites for different codes, but everywhere it is showing that it is redundant
see if you do the dry run for that test case:
then it will be done like this if character is not equal to ‘)’ then we will directly push it into the stack but if the character is ‘(’ then we will check if the character at the top is ‘(’ then only it will come under redundant but we will pop the elements until the top of the stack is not equal to ‘(’:
so in this way we will dry run for that test case: ((a+(b))+(c+d))
until first ‘)’ stack will be ((a+(b
then the first ‘)’ this will encounter and the stack will become:
((a+
and then another ‘)’ this will come then the stack will become :
(.
now we will push in the stack until character is not equal to ‘)’
then the stack will become:
(+(c+d .
after another closing stack will become :
(+and then the last closing the the stack will be eompty so it is not reduntant you can seee.
Thank you Sir,
Got the clue
But still, it is reporting the Wrong Answer on submission
Hey @NKushal please it is giving wrong answer because your code is producing Duplicate for the test case which i have discussed above but it is not duplicate.
Here for your reference i am attaching the code:
if you still have any doubt you can ask here:
Happy Learning!!
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.