Longest valid Parentheses
Submissions: 18700   Accuracy:

24.1%

  Difficulty: Hard   Marks: 8
     

Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.

Input:
First line contains number of test cases T.  Each test case have one line string S of character '(' and ')' of length  N.

Constraints:
1 <= T <= 500
1 <= N <= 105

Example:
Input:
2
((()
)()())

Output:
2
4

Explanation:
Testcase 1:
Longest valid balanced parantheses is () and its length is 2.

** For More Input/Output Examples Use 'Expected Output' option **

Author: dhruvi


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.