637. Longest Valid Parentheses

MediumStackStackDynamic ProgrammingString

Given a string s of '(' and ')', return the length of the longest contiguous substring that is a valid balanced parentheses string. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the longest valid substring length.

Examples

Example 1
Input: {"s":")()())"}
Output: 4
Explanation: The substring '()()' has length 4.
Example 2
Input: {"s":"(()"}
Output: 2
Explanation: The substring '()' has length 2.
Example 3
Input: {"s":""}
Output: 0
Explanation: Empty string.

Constraints

Asked by

MetaAmazonIBMMicrosoftBloombergGoogle
Solve this problem in the editor →