-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBi_lindrome!.cpp
More file actions
36 lines (34 loc) · 912 Bytes
/
Bi_lindrome!.cpp
File metadata and controls
36 lines (34 loc) · 912 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
#define ll long long
#define f(end) for(int i=0;i<end;i++)
#define e '\n'
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int a[26]={0},ans=0;
bool yes=false;
string s;
cin>>s;
f(s.length()) a[s[i]-'a']++;
f(26){
if(a[i]>1){
yes=true;
break;
}
}
if(yes) ans=n-2;
else ans=-1;
cout<<ans<<e;
}
return 0;
}
//the maximum subsequence can be only taken out and make smallest palindrome is when two to same characters are present
// so in this question we only need to check if there are string which are repeating 2 times so for answer we simply
// need to take out those 2 number from given n and print our answer else all are present only one time ans we
// given ans=-1