Cascadiq

Longest Valid Parentheses

algorithm · Level 3 · 35 min

Description

Given a string containing just the characters ( and ), find the length of the longest valid (well-formed) parentheses substring.

Requirements

  • Implement a function that takes a string s of '(' and ')'.
  • Return the length of the longest valid parentheses substring.

Constraints

- `0 <= s.length <= 3 * 10^4` - `s[i]` is `'('` or `')'`.

Deliverables

Return the length (number) of the longest valid substring.

Tags

StringStackDynamic Programming