3rd test case gives wrog answer

Hello @kamya,

This is because, you have missed a very important part of the question:
A string of ‘(’ , ‘)’ , ‘{’ , ‘}’ and ‘[’ , ‘]’ .

The input string consists of the above mentioned type of brackets.
But, you are considering only one type:( )

Note:

  1. Store the opening bracket all kinds in a single stack. Also, there is no need to use separate conditional checks.
  2. Use separate checks for closing brackets as the order of brackets do matters.

Hope, this would help.
Give a like, if you are satisfied.

https://ide.codingblocks.com/s/111563..2 testcases coming wrong

Hello @kamya,

The link you have shared, does not contains your code.

https://ide.codingblocks.com/s/111563 sorry,this is the code

The testcases are coming wrong because of the following code:

	else if(curChar==')'||curChar=='}'||curChar==']')
	{
		if(s.empty() ||s.top()!='('|| s.top()!='{'||s.top()!='[')
		{
			return false;
		}
		s.pop();
	}

You have to write a separate check for each type of bracket.
Reason:
Your code will accept ‘(’ for ‘}’.
But, the question requires the same kind of closing and opening brackets for the parenthesis to be balanced.

Hope, this would help.