-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1837B.cpp
More file actions
36 lines (28 loc) · 842 Bytes
/
1837B.cpp
File metadata and controls
36 lines (28 loc) · 842 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
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false); cin.tie(nullptr);
int main() {
fast_io;
int t;
cin >> t;
while (t--) {
// solve here
int n;
cin >> n;
string s;
cin >> s;
int longest_substring_length = 1;
int current_substring_length = 1;
for (int i = 1; i < n; i++){
if (s[i]==s[i-1])
current_substring_length++;
else{
longest_substring_length = max(longest_substring_length,current_substring_length);
current_substring_length = 1;
}
}
longest_substring_length = max(longest_substring_length, current_substring_length);
cout << longest_substring_length + 1 << endl;
}
return 0;
}