Created
June 5, 2020 19:44
-
-
Save Shaddyjr/f8d0b86ca8e7c1bc96ef787b6070f402 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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