Educational Codeforces Round 149 (Rated for Div. 2) 1837B - Comparison String Solution
Problem Link : https://codeforces.com/problemset/problem/1837/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t; cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- string s ;
- cin >> s;
- int ans = 0 , cnt = 1 ;
- for ( int i = 0 ; i < n ; i++) {
- if (s[i] == s[i+1]) cnt++ ;
- else {
- ans = max(ans,cnt);
- cnt = 1 ;
- }
- }
- cout << ans + 1 << '\n';
- }
- return 0 ;
- }
No comments