i have included all the mentioned cases in comments, however when i include those comments the first two text cases fail. please help.
Test case 2 not pasing
@sans_sehgal hey sanskar I canβt see your code please share your code directly copy and paste here
#include #include #include using namespace std; bool checkValid(string s) { stack stc; for(int i=0; i<s.length(); i++) { if(s[i]==β(β) stc.push(β(β); else if(s[i]==β)β) { if(!stc.empty()) stc.pop(); else { return false; break; } } } return stc.empty(); } int main() { string s; getline(cin , s); if(checkValid(s)==1) cout<<βyesβ; else cout<<βnoβ; }
#include #include #include using namespace std; bool checkValid(string s) { stack stc; for(int i=0; i<s.length(); i++) { if(s[i]==β(β || s[i]== β{β || s[i]==β[β) { stc.push(β(β); } else if(s[i]==β)β || s[i]== β}β || s[i]==β]β) { if(!stc.empty()) stc.pop(); else { return false; break; } } } return stc.empty(); } int main() { string s; getline(cin , s); if(checkValid(s)==1) cout<<βYesβ; else cout<<βNoβ; }
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.