Game of Thrones - I

  • + 0 comments

    My C++ Solution: (gist is: To make a string into palindrome - there should not be multiple characters with odd freq)

    string gameOfThrones(string s) {
        char arr[26] ={0};
        bool odd = false; 
        
        for(int i=0; i<s.size(); i++){
            if(arr[s[i]-'a']){
                arr[s[i]-'a']--;
            }else{
                arr[s[i]-'a']++;
            }
        }
        for(int i=0; i<26; i++){
            if(arr[i]%2 != 0 ){
                if( odd == true)
                    return "NO";
                else odd = true;
            }
        }
        return "YES";
    }