#include <bits/stdc++.h>
using namespace std;
bool checkexp(string str)
{
stack s;
for(int i=0;i< str.size();i++)
{
char currentchar=str[i];
if(currentchar==’(’)
{
s.push(currentchar);
}
else if(currentchar==’)’){
if(s.empty() || s.top()!=’(’)
{
return false;
}
s.pop();
}
}
return s.empty();
}
int main() {
string exp;
cin>>exp;
bool isvalid=checkexp(exp);
if(isvalid==1)
cout<<“Yes”;
else
cout<<“No”;
return 0;
}
only one test case is not passing why
Balanced parathsis
@prajjwalrkstr hey prajjwal there is basically three cases (,{,[ and you’re doing for only ( handle all the cases.
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.