Longest Valid Parenthesis:- Help required! (C++)

Why does the expected output for s = "()(()" is 2 ? Shouldn't it be 4 as it it is clear that there are 2 sets of valid '()' ?

Comments (1)