Why isnt this working? (C++)

int Solution::solve(string A) {
    unordered_set<string> set;
    for(int i = 0; i<A.size(); i++){
        if(set.find(A[i]) != set.end()){
        else set.insert(A[i]);
    if(set.size() <= 1) return 1; //only 1 non pair left(eg. c in abbcbba)
    return 0;


You created unordered set of string data type instead of that create unordered set of char data type.


You have to check for odd and even size length differently.


Works like a charm. Thank you :slight_smile: