Longest Valid Parentheses

Hard
Strings Stack DP
Find the length of the longest valid parentheses substring. Input: parentheses string Output: length

Constraints

See problem-specific constraints. Optimized solution required.

Examples

Example 1:
Input: (()
Output:
Example 2:
Input: (()
Output:

Hints

Consider a stack approach.
Think about time complexity.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.