Longest Valid Parentheses
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.

30:00

Longest Valid Parentheses
hard
Topics
Companies

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

Example 1:
Input: "(()"
Output: 2
Constraints:
  • 0s.length3×1040 \leq s.\text{length} \leq 3 \times 10^4

  • s[i] is '(' or ')'.

Input
arr ="(()"

Initialize stack with -1 as base index

(

0

(

1

)

2

Stack (indices)

-1

Index:

-1

Max Length:

0

Current

Valid

In Stack

Variables
No variables to display
DepthFunction Call
Stack empty
0/4