Longest Valid Parentheses Problem
Longest Valid Parentheses Problem — ExecCode Hard DSA Practice
Solve the Longest Valid Parentheses problem on ExecCode. Free online hard DSA practice in Stack. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a string s containing only ( and ), return the length of the longest contiguous substring that forms a valid parentheses sequence.
Examples
Input ((); Output 2. Input )()()); Output 4. Input ()(()); Output 6
Constraints
0 <= s.length <= 30000
Practice Longest Valid Parentheses free on ExecCode. Browse DSA problems, topic map, and placement guides.