The Minion Game

Sort by

recency

|

1246 Discussions

|

  • + 0 comments

    We can apply one final small optimisation in this problem, as we know that the sum of Stuart and Kevin's points for a given string is constant (equal to ((n + 1)n/2), where (n) is the length of the string). Therefore, we can skip keeping track of, for example, Stuart's points and, at the end, subtract Kevin's points from the known total.

  • + 0 comments
    def minion_game(string):
    
        score_player_one = 0
        score_player_two = 0
        
        for x in range(len(string)):
            if isvowels(string[x]):
                score_player_two += (len(string)) - x
            else:
                score_player_one += (len(string)) - x
           
        print_score(score_player_one,score_player_two)
            
    def isvowels(letter):
        vowels = "AEIOU"
        return vowels.__contains__(letter)
          
    def print_score(score_player_one, score_player_two):
        if(score_player_one > score_player_two):
            print(f"Stuart {score_player_one}")
        elif(score_player_one < score_player_two):
            print(f"Kevin {score_player_two}")
        else:
            print("Draw")    
    
  • + 0 comments

    def minion_game(string): vowel = 'AIUEO' kevin = 0 stuart = 0

    if string.isupper() == True and 0 < len(string) <= 10**6:
        for i in range(len(string)):
            if string[i] not in vowel:
                stuart += len(string) - i
            else:
                kevin += len(string) - i
    
    if kevin > stuart:
        print("Kevin", kevin)
    elif kevin < stuart:
        print("Stuart", stuart)
    else:
        print("Draw")
    
  • + 0 comments

    My solution involves iterating over the string and check if the character in question is a consonant or a vowel. If the character is a vowel then the length of the substring from that character till the end of the string is to be added to kevin's last recorded score. This is because for each possible substring 1 point is awarded, so if you have a string 'abcd', here 'a', 'ab', 'abc' and 'abcd' substrings will go into kevin's favour, which means he will gain 4 points from all the substrings starting from 'a' and 4 is also the length of the substring starting from 'a' till the very end of the string. Similarly, while iterating over the string if the character is a constant then the length of the substring from the character till the end of the string is to be added to stuart's last known score. After the iteration is complete then the scores are compared and the appropriate result is displayed.

    def minion_game(string):
        kevin_score=stuart_score=0
        length=len(string)
        for index, char in enumerate(string):
            if char in 'AEIOU':
                kevin_score+=length-index
            else:
                stuart_score+=length-index
        if kevin_score>stuart_score:
            print(f'Kevin {kevin_score}')
        elif stuart_score>kevin_score:
            print(f'Stuart {stuart_score}')
        else:
            print('Draw')
    
  • + 0 comments
        consonants = 0
        s = string.upper()
        if len(s)>0 and len(s)<=(10**6):
            for i in range(len(s)):
                if s[i] in ['A','E','I','O','U']:
                    vowels += len(s) - i
                else:
                    consonants += len(s) - i
            if vowels > consonants:
                print('Kevin',vowels)
            elif vowels < consonants:
                print('Stuart',consonants)
            else:
                print('Draw')