Matched Brackets

Code:

Logic:
depth – nesting depth
di – first position that achieves nesting depth
span – length of maximum sequence
si – first position of the maximum sequence.
dc – temporary holder for number of the nesting depth, keep increasing while meeting “(” and restart from 0 once encounter “)”. depth = dc when dc > current depth.
sc – increase by one for every “(”, decrease by one for every “)”. Equals 0 when the bracket is closed.
st – temporary count for length of sequence. When a pair of brackets is closed (sc = 0), check if st > span; if it does, span = st.
tsi – temporary index of maximum sequence index. si = tsi only when span = st (current sequence becomes new maximum sequence).

Please help me figure out why my code didn’t work.

The link you provided is the link to your submissions tab , give the link to your code

Nevermind your code fails on this input

14
1 2 1 1 1 2 1 1 1 2 2 2

Your output :

3 5 12 3

Correct output :

5 9 12 3
1 Like

Oh I see the problem now. Thank you!