Jun-27-2020, 06:58 PM
(This post was last modified: Jun-27-2020, 06:58 PM by Emekadavid.)
(Jun-27-2020, 04:25 PM)deanhystad Wrote: This is a really expensive way to do very simple mathI decided to look into the model/logic based on what you said and removed the loop. Look at the new code. But the test cases still say that it did not execute within the time limit. Please, if you can help just help me.
for j in range(i, len(text)): countConsonants += 1This is a logic problem, not a programming problem. Step away from the computer and think about how to solve the problem, not how you would write a program to solve the problem.
def count_cons(text, vowels): countVowels = 0 countConsonants = 0 textlength = len(text) for i in range(textlength): if text[i] not in vowels : countConsonants += len(text[i:]) else : if text[i] in vowels : countVowels += len(text[i:]) if countConsonants > countVowels : print('Stuart', countConsonants) elif countVowels > countConsonants : print('Kevin', countVowels) else : print('Draw') def minion_game(string): # your code goes here assert 0<len(string)<=1000000 vowels = 'AEIOU' count_cons(string, vowels) if __name__ == '__main__': s = input() minion_game(s)If anyone can give me the concept I am missing in order to optimize the code to run within a very short time, I will research it and try it out. That is why I came here.