Tap here to switch tabs
Problem
Submissions

Problem: Longest Valid Parentheses

Longest Valid Parentheses asks you to find the length of the longest contiguous substring whose opening and closing parentheses are balanced and correctly nested.

Statement

You are given a string composed entirely of ‘(’ and ‘)’ characters. Your goal is to identify the longest contiguous segment (substring) within this string that represents a “well-formed” or “valid” sequence of parentheses.

A substring is considered valid if:

  1. Every opening parenthesis ‘(’ has a corresponding closing parenthesis ‘)’.

  2. The pairs of parentheses are correctly nested.

Return the length of this longest valid substring.

Constraints:

  • 0≤0 \leq s.length ≤3×103\leq 3 \times 10^3

  • s[i] is ‘(’, or ‘)’.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Valid Parentheses

Longest Valid Parentheses asks you to find the length of the longest contiguous substring whose opening and closing parentheses are balanced and correctly nested.

Statement

You are given a string composed entirely of ‘(’ and ‘)’ characters. Your goal is to identify the longest contiguous segment (substring) within this string that represents a “well-formed” or “valid” sequence of parentheses.

A substring is considered valid if:

  1. Every opening parenthesis ‘(’ has a corresponding closing parenthesis ‘)’.

  2. The pairs of parentheses are correctly nested.

Return the length of this longest valid substring.

Constraints:

  • 0≤0 \leq s.length ≤3×103\leq 3 \times 10^3

  • s[i] is ‘(’, or ‘)’.