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.
Instead of generating all possible substrings and storing them in a dictionary, you can take advantage of the fact that you don't need the actual substrings. You just need to count the number of substrings that start with a vowel or consonant.
To make it efficient:
If you consider a character at position i in the string, the number of substrings that start at i is equal to n - i, where n is the length of the string.
Based on this, if the character is a vowel, Kevin will get n - i points for that character.
Similarly, if it is a consonant, Stuart will get n - i points for that character.
This approach avoids explicitly generating substrings and directly calculates the scores.
The Minion Game
You are viewing a single comment's thread. Return to all comments →
Instead of generating all possible substrings and storing them in a dictionary, you can take advantage of the fact that you don't need the actual substrings. You just need to count the number of substrings that start with a vowel or consonant.
To make it efficient:
If you consider a character at position i in the string, the number of substrings that start at i is equal to n - i, where n is the length of the string. Based on this, if the character is a vowel, Kevin will get n - i points for that character. Similarly, if it is a consonant, Stuart will get n - i points for that character. This approach avoids explicitly generating substrings and directly calculates the scores.