Hello fellow programmers!
I was trying to solve this question, which is based on stack implementation. . I wonder why i am getting WA for my code, if someone can provide counter test cases or bug in my code, it would be really helpful.
Thanks.
Here is link to my code
#include
#include
#include
using namespace std;
int main(){
int t;
cin >> t;
getchar();
while(t–){
string str;
stack s;
getline(cin,str);
bool result = true;
for(auto ch : str){
if(ch==‘M’){
if(s.size()>=2){
char ch1 = s.top();
s.pop();
char ch2 = s.top();
s.pop();
if((ch1==‘E’) && (ch2==‘I’)){
continue;
}
else{
result = false;
break;
}
}
}
else s.push(ch);
}
if(result==false||s.size()>0) cout << "No\n";
else if(result == true && s.size()==0)cout << "Yes\n";
//if(s.empty()) cout << "Yes\n";
//else cout << "No\n";
}
}