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
Core interview problems are free with a full runner and lessons; Pro opens the complete library.