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.
I had some trouble with run time errors initially, I was making it way more complex than it had to be. I find it helpful to note that the number of subsets starting with a letter is: the length of the string - the index of the letter.
I.e. if the string is 'banana', the number of subsets starting with 'b' is len('banana')-index('b') = 6-0 = 6 : [b, ba, ban, bana, banan, banana]
Using this method you can add the number of subsets starting with each vowel, and the same with each non-vowel.
for i in range(len(string)):
if string[i] in v:
c1 = c1 + len(string) - i
else:
c2 = c2 + len(string) - i
You could also make two seperate lists - one with the indicies of each vowel, and one with the indicies of each non-vowel. Then get the scores by calculating the length of the string * length of the list of indicies - sum of the list of indicies.
for i in range(len(string)):
if string[i] in v:
a.append(i)
else:
b.append(i)
c1 = len(string)*len(a) - sum(a)
c2 = len(string)*len(b) - sum(b)
Then you can determine the winner by comparing the scores.
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 →
I had some trouble with run time errors initially, I was making it way more complex than it had to be. I find it helpful to note that the number of subsets starting with a letter is: the length of the string - the index of the letter. I.e. if the string is 'banana', the number of subsets starting with 'b' is len('banana')-index('b') = 6-0 = 6 : [b, ba, ban, bana, banan, banana]
Using this method you can add the number of subsets starting with each vowel, and the same with each non-vowel.
You could also make two seperate lists - one with the indicies of each vowel, and one with the indicies of each non-vowel. Then get the scores by calculating the length of the string * length of the list of indicies - sum of the list of indicies.
Then you can determine the winner by comparing the scores.