s contains only ( and ). Return the length of the longest substring (consecutive characters) that is a valid parentheses string (every ( closed in the right order).
For ")()())" the answer is 4.
The starter code checks every substring. It is correct but too slow for long strings.
Example 1
Input:
longest_valid_parentheses(')()())')
Output:
4
Example 2
Input:
longest_valid_parentheses('(()')
Output:
2
0 <= len(s) <= 200000No results yet
Run your code to check it against the examples, or submit to run every test.