Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <algorithm>
- #define lli long long int
- #define li long int
- #define vi vector<int>
- #define mod 1000000007
- #define ld long double
- #define F first
- #define S second
- #define PB push_back
- #define MP make_pair
- #define REP(i, a, b) for (int i = a; i < b; i++)
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- lli t;
- cin >> t;
- while (t--)
- {
- string s;
- cin >> s;
- lli p = s.size();
- vi vec;
- lli ct = 0;
- for (lli i = 0; i < s.size(); i++)
- {
- if (s[i] != s[0] && s[i] != s[p - 1])
- {
- ct++;
- }
- else
- {
- ct = 0;
- }
- vec.PB(ct);
- }
- lli h = *max_element(vec.begin(), vec.end());
- if (h == 0)
- {
- cout << -1 << endl;
- }
- else
- cout << h << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment