O(n) solution with easy understanding with o(1) space


#1

int Solution::anytwo(string A)
{
//count occurence of each char
//if occurence is goes more than 2 than return 1;
int m[256]={0};
for(auto x:A)
if(++m[x]>2)
return 1;

//create extra string with occurence 2 is same as greater than 1;            
string tmp="";
for(auto x:A)
    if(m[x]>1)
        tmp+=x;

//other extra string which is reverse of previos
string rtmp=tmp;
reverse(rtmp.begin(),rtmp.end());

//if string is palindrom than return false 0;
if(tmp==rtmp)
    return 0;

//most of the time u will get 1 ;)
return 1;

}


#2

Awesome logic man!..Nice