Find the longest sequence of multiple Parentheses

Iqram Ali
3 min readNov 8, 2020

Problem statement: Given a string s consisting of open and closed brackets "(" and ")", return the length of the longest substring in s that is a valid string of parentheses.

Example 1

Input

s = ")(())(()"

Output

4

Explanation

"(())" is the longest substring with valid parentheses.

Naive approach: Find all the substrings of a given string. For every string, check…

--

--

Iqram Ali

Developer influencer, 15+ years in software development currently in engineering leadership role.