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:
- Store the opening bracket all kinds in a single stack. Also, there is no need to use separate conditional checks.
- Use separate checks for closing brackets as the order of brackets do matters.
Hope, this would help.
Give a like, if you are satisfied.
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.