#include
#include
using namespace std;
bool checkbalancedparanthesis(string str){
stack s;
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 exp;
cin>>exp;
bool isvalid=checkbalancedparanthesis(exp);
if(isvalid){
cout<<βYesβ;
}
else
cout<<βNoβ;
}
why it is not passing all test casesβ¦
Balanced parathensis
@tishya_goyal
You are given a string of brackets i.e. β{β, β}β , β(β , β)β, β[β , β]β .
There are other types of brackets as well.