+ 1

Balanced parentheses

https://code.sololearn.com/cHHlx7KjMQHr/?ref=app Why does the last testcase fail ?

15th Oct 2022, 1:42 PM
Sanjay Kamath
Sanjay Kamath - avatar
5 Answers
+ 11
Snehil Pandey , your comment could be misunderstood. ')(a+b)(' this string contains the same nunber of opening and closing parenthesis, but it is not what is called *ballanced*. this is ballanced: '()' thus is not ballanced: ')('
15th Oct 2022, 3:29 PM
Lothar
Lothar - avatar
+ 4
Think of case like : )(a+b)(
15th Oct 2022, 1:44 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 is right There should be same number of opening as well as closing parenthesis
15th Oct 2022, 1:45 PM
Random
Random - avatar
15th Oct 2022, 5:23 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Sanjay Kamath Your approach finding Number of '(' is equal to Number of ')' . But you should also consider the order. See my example: )(a+b)( It has 2 '(' and 2 ')' but those are not in proper way.. You need to rethink about your logic. Some changes needed.. Today only I discussed about same task and what is it how to do in another this thread. Have a look. You may get idea how to correct your code.. Hope it helps.. https://www.sololearn.com/discuss/3094127/?ref=app
15th Oct 2022, 6:53 PM
Jayakrishna 🇮🇳