The Minion Game – One-Liner Version

Опубликовано: 07 Май 2026
на канале: CodeVisium
54
1

This solution provides a compact one-liner approach to solve "The Minion Game." In this game, Kevin and Stuart earn points based on the number of substrings they can form from a given string. Kevin scores with substrings starting with vowels (A, E, I, O, U), while Stuart scores with those starting with consonants. Instead of generating all substrings (which would be inefficient), this solution leverages the insight that for any character at index i in a string of length n, there are exactly (n - i) possible substrings starting from that index.

The one-liner:

Reads the input string.

Calculates Kevin’s score by summing (n - i) for each index i where the character is a vowel.

Calculates Stuart’s score similarly for consonants.

Finally, it prints the winner and their score, or "Draw" if the scores are equal.

This approach demonstrates the power of Python’s concise syntax, list comprehensions, and inline conditionals, making it a great solution for competitive programming and interview preparation.

Code (One-Liner Version):

if _name_ == '__main__':
s = input().strip()
n = len(s)
kevin = sum(n - i for i in range(n) if s[i] in "AEIOU")
stuart = sum(n - i for i in range(n) if s[i] not in "AEIOU")
print("Kevin", kevin) if kevin v stuart else print("Stuart", stuart) if stuart v kevin else print("Draw")