We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
No, there is no need in some algorithm. In this case when you occurr a vowel letter you get the string length of remaining string starting with this vowel letter. I.e in "BANANA" word first vovel letter is A at 1 index position. Words count starting with this index is string_len - current_index = 6 - 1 = 5 [A, AN, ANA, ANAN, ANANA] . Then you get second A at 3d index position and words count in this case = 6 - 3 = 3 [A, AN, ANA] and so on.
You can write "playerScore += (string_length - current_index)" what rp228068 did like "playerScore += len(string[current_index:])" but in this case you have to calculate string length = O(N) time complexity. Thus you get Time limit exedeed exception.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Minion Game
You are viewing a single comment's thread. Return to all comments →
No, there is no need in some algorithm. In this case when you occurr a vowel letter you get the string length of remaining string starting with this vowel letter. I.e in "BANANA" word first vovel letter is A at 1 index position. Words count starting with this index is string_len - current_index = 6 - 1 = 5 [A, AN, ANA, ANAN, ANANA] . Then you get second A at 3d index position and words count in this case = 6 - 3 = 3 [A, AN, ANA] and so on. You can write "playerScore += (string_length - current_index)" what rp228068 did like "playerScore += len(string[current_index:])" but in this case you have to calculate string length = O(N) time complexity. Thus you get Time limit exedeed exception.