Difficulty in understanding the problem Matched Brackets

I was trying to solve he Matched Brackets problem but I am not understanding the second part of the question which says.

The maximum number of symbols between any pair of matched brackets, including both the outer brackets, and the first position where this occurs–that is, the position of the first opening bracket of this segment.

Anyone please help me in understanding this problem.

maximum number of symbols between any pair of matched brackets” means you just have to find out the maximum number of parenthesis both opening and closing ones that are present in a well bracketed sequence. For example, in the below string:

()(())()(()())(()()) 

You have (), (()), (), (()()), and (()()) well bracketed sequences with counts of 2, 4, 6, 6. The “first” maximum occurs are position 9 that’s why you have to report 2 4 6 9 which is

{<maximum nesting depth>, <position of FIRST well-bracketed sequence with the maximum nesting depth>, <maximum 
 number of brackets in a well-bracketed sequence>, <starting position of such a sequence>}

Hope it helps. Let me know if you have any further doubts.

Regards,

2 Likes

@utkalsinha

=4, how?

and “(())” this also have the nesting depth of 2, then why aren’t we considering this.

@taran_1407 @vijju123 @vivek_1998299 @a_d_i @vsr625 @ayan_nitd

please help

For Maximum nesting depth you have to enter the position of first opening bracket with the maximum depth. For sequence

()(())()(()())(()())

In the other way we can say that it is opening bracket before the first closing bracket at the maximum nesting depth. Like in this example it is 4 if starting from 1.

If the sequence would be

(()())

then the answer would be 2 instead of 4 because 2 is the opening bracket before the first closing bracket at the maximum nesting depth.

For Maximum Symbol, It is the maximum number of symbol between an opening bracket and its corresponding closing bracket including both the opening and closing bracket. For eg.

() - 2 symbols

(()()) - 6 symbols

(()) - 4 symbols

and the first position will be the position of the first opening bracket which contains the symbols. For eg.

()(())(()()) - In this the maximum symbols will be 6 and position will be 7 if starting from 1.