Hard
Quiz
#32 Longest Valid Parentheses
APPROACH
Given a string of only '(' and ')', return the length of the longest contiguous substring that forms a valid, well-balanced parentheses sequence.
Example 1:
Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".
Example 2:
Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".
Example 3:
Input: s = ""
Output: 0
1 of 4
1:00
What is the optimal approach for this problem?