Update appNew update is available. Click here to update.

Longest Bracket

Last Updated: 28 Nov, 2020
Difficulty: Moderate

PROBLEM STATEMENT

Try Problem

You are given a string S, consisting of only '(' and ')' characters. You need to find the length of the longest substring which is a regular bracket sequence and also find the count of such substrings with the same length.

Note:

A bracket sequence is called regular, if parenthesis in the given expression is balanced.  For example '()()', '(())' are the regular string but '((()' is not a regular parenthesis string.

If no such substring exists, print "0 1" (without quotes).

Input format :

The first line of input contains an integer ‘T’, which denotes the number of test cases. Then each test case follows. 

Each line of the test case contains a string having characters ‘(‘ or ‘)’ in it.
Output format :
For each test case print, 2 space-separated integers representing the length of the longest substring with regular bracket sequence and the number of such substrings present in the input string.

Note:

Update the length of the longest regular bracket substring in the variable ‘length’ and store the count of such substring in variable ‘count’ passed as parameters in the given function.
Constraints :
1 <= T <= 5
1 <= N <= 10 ^ 4


Time Limit : 1 sec.

Note :

You don’t need to print anything, it has already been taken care of. Just implement the given function.