-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path312.cpp
More file actions
40 lines (37 loc) · 869 Bytes
/
Copy path312.cpp
File metadata and controls
40 lines (37 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// { Driver Code Starts
// Initial template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function template for c++
class Solution {
public:
int findMaxLen(string s) {
int i,n=s.size(),l1=0,r1=0,l2=0,r2=0,c1=0,c2=0,m1=0,m2=0;
for(i=0;i<n;i++)
{
s[i]=='('?l1++:r1++;
s[n-i-1]==')'?r2++:l2++;
r1>l1?l1=r1=0:0;
l2>r2?l2=r2=0:0;
r1==l1?c1=l1:0;
r2==l2?c2=l2:0;
m1=max(m1,c1*2);
m2=max(m2,c2*2);
}
return max(m1,m2);
}
};
// { Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
string S;
cin >> S;
Solution ob;
cout << ob.findMaxLen(S) << endl;
}
return 0;
}
// } Driver Code Ends