-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBoringString.cpp
More file actions
37 lines (36 loc) · 787 Bytes
/
BoringString.cpp
File metadata and controls
37 lines (36 loc) · 787 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
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
string str;
cin>>str;
map<pair<char,int>,int>f;
char curr=str[0];
int length=1;
f[{curr,length}]++;
for(int i=1;i<n;i++){
if(curr!=str[i]){
length=1;
curr=str[i];
}
else length++;
f[{curr,length}]++;
}
int maxi=0;
for(auto &it:f){
if(it.second==1){
maxi=max(maxi,it.first.second-1);
continue;
}
else
maxi=max(maxi,it.first.second);
}
cout<<maxi<<endl;
}
// your code goes here
return 0;
}