We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Balanced Brackets
Balanced Brackets
Sort by
recency
|
1632 Discussions
|
Please Login in order to post a comment
What's the issue?
include
using namespace std; void printstack(stack s){ while(!s.empty()){ cout< st; bool t=true; for (auto ch:s){ if ((ch=='(')||(ch=='[') || (ch=='{')){ st.push(ch); //printstack(st); }else{ if ((ch==')') && (st.top()=='(')){ st.pop(); }else if((ch==']') &&(st.top()=='[')){ st.pop(); }else if((ch=='}') && (st.top()=='{')){ st.pop(); }else{ return "NO"; } } }
} int main(){ int t; cin>>t; while(t--){ string s; cin>>s; cout<
I try a recursive solution just for fun (won't pass the test cases)
Fairly simple Stack based problem. Nothing too complex.
Here's my Java 8 solution, passing all test cases, for Max Score of 25:
C++: its run correctly in my compiler but when i run it on hackerrank it shows me that all test cases are wrong, and i try all of the test cases and it run correct on my compiler, i dont know what to do!!