Game of Thrones - I

Sort by

recency

|

1074 Discussions

|

  • + 0 comments

    Here is my c++ solution : explanation here : https://youtu.be/yhSaL48IHds

    solution 1 :

    string gameOfThrones(string s) {
        map<char, int> mp;
        for(int i = 0; i < s.size(); i++){
            if(mp[s[i]] != 0){
                mp[s[i]]--;
                if(mp[s[i]] == 0) mp.erase(s[i]);
            }
            else mp[s[i]]++;
        }
        if(mp.size() > 1) return "NO";
        return "YES";
    }
    

    solution 2 :

    string gameOfThrones(string s) {
        map<char, int> mp;
        for(int i = 0; i < s.size(); i++){
            if(mp[s[i]] == 1)  mp.erase(s[i]);
            else mp[s[i]]++;
        }
        if(mp.size() > 1) return "NO";
        return "YES";
    }
    
  • + 0 comments

    One liner.

    def gameOfThrones(s):

    return "NO" if sum([1 for i in [s.count(i) for i in set(s)] if i % 2 != 0]) > 1 else "YES"

  • + 0 comments

    Python 3

    from collections import Counter
    
    def gameOfThrones(s):     
        # Write your code here
        counts_s = Counter(s)
    
        vals = counts_s.values()
    
        uneven_count = 0
        for ii in vals:
            if ii % 2 != 0:
                uneven_count +=1 
    
        if uneven_count > 1:
            return "NO"
        else:
            return "YES"
    
  • + 0 comments

    for Python3 Platform

    import collections
    
    def gameOfThrones(s):
        d = collections.Counter(s)
        multipleOddVal = False
        
        for val in d.values():
            if (val % 2 == 1):
                if (multipleOddVal):
                    return "NO"
                    break
                else:
                    multipleOddVal = True
        else:
            return "YES"
    
    s = input()
    
    result = gameOfThrones(s)
    
    print(result)
    
  • + 0 comments

    string gameOfThrones(string s) { const int range = 'z' - 'a' + 1; size_t pairTable[range] = {0}; for(auto & chr : s) { pairTable[chr - 'a'] ^= 1; } size_t sum = 0; for(size_t idx = 0; idx < range; idx++) { sum += pairTable[idx]; } if((s.length() % 2) == sum) { return "YES"; } return "NO"; }