Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created June 5, 2020 19:44
Show Gist options
  • Save Shaddyjr/f8d0b86ca8e7c1bc96ef787b6070f402 to your computer and use it in GitHub Desktop.
Save Shaddyjr/f8d0b86ca8e7c1bc96ef787b6070f402 to your computer and use it in GitHub Desktop.
# source - https://www.hackerrank.com/challenges/the-minion-game/problem
def minion_game(string):
VOWELS = "aeiou" # y not considered a vowel
KEVIN_vowels = 0
STUART_consonants = 0
n = len(string)
for i in range(n): # O(n)
letter = string[i].lower() # ensuring lowercase comparisons
letters_remaining = n - i
if letter in VOWELS: # O(5)
KEVIN_vowels += letters_remaining
else:
STUART_consonants += letters_remaining
if STUART_consonants == KEVIN_vowels:
print("Draw")
elif STUART_consonants > KEVIN_vowels:
print("Stuart", STUART_consonants)
else:
print("Kevin", KEVIN_vowels)
# TOTAL TIME COMPLEXITY = O(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment