From 60e8a270d909646d4c5fff0d4d2ca4c9cfed323c Mon Sep 17 00:00:00 2001 From: Mayank Tiwari <68435389+MAYANK22122002@users.noreply.github.com> Date: Thu, 31 Jul 2025 20:36:59 +0530 Subject: [PATCH] Update 3-2.cpp Sir , In balanced and unbalanced parenthesis question it was failing one test case so I have done some changes in it and now it is working fine. Review the code sir if it is correct or not. --- 3-2.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/3-2.cpp b/3-2.cpp index 1594f09..18cdcd7 100644 --- a/3-2.cpp +++ b/3-2.cpp @@ -154,6 +154,7 @@ int main() { string s = "()("; stack st; + bool isBalanced = true; for(char c: s) { @@ -161,18 +162,23 @@ int main() { st.push(c); } - else + else if(c==')') { if(st.empty()) { + isBalanced=false; break; } + else + { + st.pop(); + } + - st.pop(); } } - if(st.empty()) + if(st.empty() && isBalanced) { cout << "Balanced"; }