- 3

Who can solve ??

Parentheses are balanced, if all opening parentheses have their corresponding closing parentheses. Given an expression as input, we need to find out whether the parentheses are balanced or not. For example, "(x+y)*(z-2*(6))" is balanced, while "7-(3(2*9))4) (1" is not balanced. The problem can be solved using a stack. Push each opening parenthesis to the stack and pop the last inserted opening parenthesis whenever a closing parenthesis is encountered. If the closing bracket does not correspond to the opening bracket, then stop and say that the brackets are not balanced. Also, after checking all the parentheses, we need to check the stack to be empty -- if it's not empty, then the parentheses are not balanced. Implement the balanced() function to return True if the parentheses in the given expression are balanced, and False if not. Sample Input: (a( ) eee) ) Sample Output: False

22nd Feb 2022, 4:22 PM
Muhammad Samadi
Muhammad Samadi - avatar
16 Respostas
+ 1
Muhammad instead of talking about the solution, I hope if you can try your attempt, share your code and we will follow your work..
22nd Feb 2022, 4:45 PM
Amine Laaboudi
Amine Laaboudi - avatar
0
Muhammad This looks like homework. It is customary to attach your code attempt when trying to resolve a problem like this
22nd Feb 2022, 4:26 PM
Amine Laaboudi
Amine Laaboudi - avatar
0
Which challenge is it like to give a shot
22nd Feb 2022, 4:32 PM
Ion Kare
Ion Kare - avatar
0
Muhammad and also I don't see any needs to use stack if your task is just to check if a parentheses string balanced or not,.. so try your attempt and then if you face other difficulties poste it here..
22nd Feb 2022, 4:37 PM
Amine Laaboudi
Amine Laaboudi - avatar
0
Right the way i would solve is is Count the "(" with .find"()" and find ")(" see if it == even number etc.. idk how it would work but thats how i would go about. Not on python data yet
22nd Feb 2022, 4:42 PM
Ion Kare
Ion Kare - avatar
0
Ok thank you I think you are right it may be it will help me Now I want to complete python code after that I will finish that
22nd Feb 2022, 4:51 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
No dear because I didn't any attempt
22nd Feb 2022, 4:27 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
Yeah this is from a challenge in sololearn but I cannot slice it
22nd Feb 2022, 4:28 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
In python data structure !
22nd Feb 2022, 4:33 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
Python data structure and last project
22nd Feb 2022, 4:36 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
Can you write the code Because I didn't know even a little
22nd Feb 2022, 4:39 PM
Muhammad Samadi
Muhammad Samadi - avatar
- 1
I know code a little but I can solve this challenge
22nd Feb 2022, 4:42 PM
Muhammad Samadi
Muhammad Samadi - avatar