Problems / Longest Valid Parentheses
Hard

Longest Valid Parentheses

Hard 5 submissions 50 coins +200 XP
Dynamic Programming Stack String
Problem Description
`s` contains only `'('` and `')'`. Return the length of the longest contiguous substring that is a well-formed parentheses string. **Example 1:** ``` Input: s = "(()" Output: 2 ``` **Example 2:** ``` Input: s = ")()())" Output: 4 ``` **Example 3:** ``` Input: s = "" Output: 0 ```
Constraints
- `0 <= s.length <= 3 * 10^4`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share