Codeforces Round 828 (Div. 3) 1744C - Traffic Light Solution
Problem Link : https://codeforces.com/contest/1744/problem/C
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;
- char c;
- cin >> n >> c;
- string s;
- cin >> s;
- s += s;
- int lg = -1;
- for (int i = 2 * n - 1; i >= n; i--) {
- if (s[i] == 'g') lg = i;
- }
- int ans = 0;
- for (int i = n - 1; i >= 0; i--) {
- if (s[i] == 'g') lg = i;
- if (s[i] == c) ans = max(ans, lg - i);
- }
- cout << ans << "\n";
- }
- return 0;
- }
No comments