Problem statement: Given a string s
consisting of open and closed brackets "("
and ")"
, return the length of the longest substring in s
that is a valid string of parentheses.
Example 1
Input
s = ")(())(()"
Output
4
Explanation
"(())"
is the longest substring with valid parentheses.
Naive approach: Find all the substrings of a given string. For every string, check…