The Minion Game

Sort by

recency

|

1329 Discussions

|

  • + 0 comments

    This is the best ans :

    for i in range(n): if string[i] in vowels: kevin += n - i else: stuart += n - i

    if stuart > kevin: print("Stuart", stuart) elif kevin > stuart: print("Kevin", kevin) else: print("Draw")

  • + 0 comments

    This is the best ans :

    for i in range(n): if string[i] in vowels: kevin += n - i else: stuart += n - i

    if stuart > kevin: print("Stuart", stuart) elif kevin > stuart: print("Kevin", kevin) else: print("Draw")

  • + 3 comments

    The Minion Game – Efficient Approach

    To solve The Minion Game, generating all substrings is not required and will cause performance issues for large strings.

    The key idea is that each character contributes to multiple substrings based on its position:

    If the character is a vowel, the score goes to Kevin

    If it’s a consonant, the score goes to Stuart

    The number of substrings starting at index i is len(string) - i

    Using this logic, the problem can be solved in O(N) time with a single loop.

    def minion_game(string): vowels = "AEIOU" kevin = 0 stuart = 0 n = len(string)

    for i in range(n):
        if string[i] in vowels:
            kevin += n - i
        else:
            stuart += n - i
    
    if stuart > kevin:
        print("Stuart", stuart)
    elif kevin > stuart:
        print("Kevin", kevin)
    else:
        print("Draw")
    

    This approach avoids substring creation and works efficiently for all test cases.

  • + 0 comments

    def minion_game(string): # your code goes here stuart_score = 0 kevin_score = 0 score = 0 vowels = 'aeiou' for i in range(len(string)): score = len(string) - i if string[i].lower() in vowels: kevin_score += score else: stuart_score += score

    if kevin_score > stuart_score:
        print(f"Kevin {kevin_score}")
    elif kevin_score < stuart_score:
        print(f"Stuart {stuart_score}")
    else:
        print("Draw")
    
  • + 0 comments

    def minion_game(string): # your code goes here a = len(string) k = 0 s = 0 for i in range(a): if string[i].lower() in ['a','e','i','o','u']: k = a-i + k else: s = s+ a-i if s > k: print((f'Stuart {s}')) elif k>s: print((f'Kevin {k}')) else: print("Draw")

    if name == 'main': s = input() minion_game(s)