Game of Thrones - I

  • + 0 comments

    Python solution O(n) time and O(k) space.

    k represent best case scenario worse case will be O(n) where every chars is added to the dictionary.

    def gameOfThrones(s):
        chars = {}
    
        for c in s:
            if c not in chars:
                chars[c] = 0
    
            if chars[c] > 0:
                chars[c] -= 1
            else:
                chars[c] += 1
                
        if sum(chars.values()) <= 1:
            return "YES"
        return "NO"