pls help with this question. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

pls help with this question.

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

6th Apr 2021, 3:37 AM
Princi Mittal
Princi Mittal - avatar
4 Answers
0
Share your attempt
6th Apr 2021, 3:42 AM
Vadivelan
0
actually i am not getting this.
7th Apr 2021, 3:53 AM
Princi Mittal
Princi Mittal - avatar
0
Try yourself. We can't give full solution. If you share attempt, we can help you easily, and better for you.
7th Apr 2021, 3:57 AM
Vadivelan
0
pls answer T_T
7th May 2021, 3:56 PM
Daniel Marasigan
Daniel Marasigan - avatar