Hard · Dynamic Programming
Longest Valid Parentheses
Given a string s made only of '(' and ')', return the length of its longest contiguous substring that is a well-formed parentheses string, or 0 if there is none.
Examples
Example 1
s = "(()"Output: length 2
Example 2
s = ")()())"Output: length 4
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.