BALANCED PARENTHESIS Testcase 3 and 4 failing

why are the test-case 3 and 4 failing ?

Your test cases are failing because you are not considering the heterogeneous sequence of parenthesis i.e. the string containing different types of parenthesis.
example:

{[}]([)

expected output: No
Your Output: Yes

This is happening because your code checked for the first parenthesis i.e. { in this case.
Then, it calls balance1()
which only checks for the occurrence of either β€˜{’ or β€˜}’ and ignores the rest of the parenthesis.

hope, this would help.
if you still have a problem, feel free to ask.
else give a like, I won’t mind.:wink:

1 Like

@S18ML0016 I rectified the problem pointed out by you but still 1 testcase is failing

I rectified the problem pointed out by you but still 1 testcase is failing

Use a single stack, rather using three different stacks.

Your code is printing β€œYes” for ([)], while it is expected to return β€œNo”.

The given string is not balanced.

Hope, this would help.

1 Like