in the video code when str[i]==’)’ they have also checked the condition whether s.top()!=’(’. is it really needed? if yes then please give a testcase where not writing this condition will give a wrong answer?
Condition necessity issue
Hello @Rj.25,
No, you can skip this conditional check s.top()!=’(’
Reason:
because stack will only contain ‘(’ brackets.
So, s.empty() is a sufficient condition.
Hope, this would help.
Give a like if you are satisfied.
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.