What is wrong with the code

#include
#include
using namespace std;
bool checkexpression(string str)
{
stacks;
for(int i=0;i<str.size();i++)
{
char curchar=str[i];
if(curchar==’(’)
{
s.push(curchar);
}
else if(curchar==’)’)
{
if(s.empty() || s.top()!=’(’){
return false;
}
s.pop();
}
}
return s.empty();
}
int main() {
string expr;
cin>>expr;
bool isvalid=checkexpression(expr);
if(isvalid)
{
cout<<β€œYes”;
}
else{
cout<<β€œNo”;
}
return 0;
}

hi @Kunalgoyal, please send your code using any online ide , due to some formatting some part of code are missing , you can use https://ide.codingblocks.com/

@Kunalgoyal, in your solution you are only considering () but in the question it is mentioned that the input can have β€˜{’, β€˜}’ , β€˜(’ , β€˜)’, β€˜[’ , β€˜]’ types of parenthesis too

now it is showing wrong answer. plz correct it.https://ide.codingblocks.com/s/268981

got it now. thanks for your help

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.