Is Question Understanding Is Wrong Or Solution Of ZCO Matched Brackets 2?

brackets
question_tackling
wa
zco12003

#1

I am solving ZCO Matched Brackets 2.


Question Link : ZCO12003


My Explanation To My Solution:



First i am checking for Maximum Alternative Depth in the first for loop.

I am checking it by taking the observation of brackets.

If i encounter bracket ( after [ or bracket [ after ( then i increment my conter by 1 and storing the maximum ans to a variable.

In second loop i am checking for the maximum number of brackets between ( ) (Inclusive) and
maximum number of brackets between [ ] (Inclusive) and printing the answer.


**My Solution: [My Code][2]**

#2

I looked at your code. I don’t think there is any issue with queries of type 2 and 3. The issue is with computation of alternating depth. Instead of giving away the error to you and spoiling the fun, let’s give you a test case for which your solution fails :wink:

Click to view

4
1 3 4 2

For this, your solution prints an alternating depth of 0. while the answer should be 2.
Happy debugging :slight_smile:

If you still have any issues, feel free to ask them.