Jun-27-2020, 07:56 PM
You are making progress, but the logic required for this problem is actually much simpler than you realize (and you are not alone, it is easy to overthink this one). Where it gets confusing is when you think of things like "N appears twice so it gets 2 points". You don't really need to parse it out that way, you just need to get the total number of substrings that start with consonants and the total that start with vowels. As long as you are getting the correct total count, you don't need to be concerned with how many times a given substring exists.
From your test case using "BANANA", you know that Stuart's score (count of substrings beginning with a consonant) is 12. Note that there are 6 substrings that begin with B (B, BA, BAN, BANA, BANAN, BANANA), 4 substrings that start with the first N (N, NA, NAN, NANA), and 2 that start with the final N (N, NA). That adds up to 12.
From your test case using "BANANA", you know that Stuart's score (count of substrings beginning with a consonant) is 12. Note that there are 6 substrings that begin with B (B, BA, BAN, BANA, BANAN, BANANA), 4 substrings that start with the first N (N, NA, NAN, NANA), and 2 that start with the final N (N, NA). That adds up to 12.