The Minion Game

  • + 0 comments

    Use a set to search for vowels, O(1) instead of O(n), n = |vowels| Also single loop instead of two loops i.e. list comprehensions.

    def minion_game(string):
        # your code goes here
        vowels = set()
        [vowels.add(x) for x in 'AEIOU']
        slen = len(string)
        volscore = 0
        conscore = 0
        for i in range(slen):
            n = slen - i
            if s[i] in vowels:
                volscore += n
            else:
                conscore += n
        if conscore > volscore:
            print(f"Stuart {conscore}")
        elif conscore < volscore:
            print(f"Kevin {volscore}")
        else:
            print("Draw")
                
    
    if __name__ == '__main__':
        s = input()
        minion_game(s