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.