Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- int testcase;
- cin >> testcase;
- while(testcase--) {
- int n;
- cin >> n;
- string s;
- cin >> s;
- if (n % 2) {
- cout << -1 << '\n';
- continue;
- }
- map <char, int> mm;
- int mx = 0;
- for (int i = 0; i < n; i++) {
- mm[s[i]]++;
- mx = max(mx, mm[s[i]]);
- }
- if (mx > (n / 2)) {
- cout << -1 << '\n';
- continue;
- }
- mm.clear();
- mx = 0;
- int c = 0;
- for (int i = 0; i < (n / 2); i++) {
- if (s[i] == s[n - i - 1]) {
- mm[s[i]]++;
- c++;
- mx = max(mx, mm[s[i]]);
- }
- }
- cout << max(mx, (c + 1) / 2) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement