Take a look at this solution O(n)


#1

//Reference gfg

int n=A.size();
int arr[256]={0};
for(int i=0;i<n;i++){
arr[(int)A[i]]++;
if(arr[A[i]]>2){
return 1;
}
}
int j=0;
for(int i=0;i<n;i++){
if(arr[A[i]]>1){
A[j++]=A[i];
}
}
string s=A.substr(0,j);
if(ispalindrome(s)){
int m=s.size();
int mid=m/2;
if(m%2==0){
return 0;
}
else if(m%2==1 && (s[mid]==s[mid-1]||s[mid]==s[mid+1])){
return 1;
}
else{
return 0;
}
}
return 1;


#2

Hey Buddy it would be really nice if you can explain the solution. Thanks in Advance.