Jun-27-2020, 11:13 PM
In your program a letter is either a vowel or it isn't (no confusion about Y) you certainly don't have to test twice.
Why are you making a substring? You know how long the string is. You know the index of the letter you are testing. Can't you come up with an equation to calculate the number of substrings? Why do you insist on counting when math is much faster?
If you have a string of length N, how many different substrings can you make that start with string[i]? Present answer in the form of an equation. Instead of solving a simple equation you would rather count from 0 to 9,999 in a loop and then do it again from 1 to 9,999, 1 to 9,999. Now you want to make a substring that is 10,000 characters long, then 9,999 characters long, then 9,998, etc...
No wonder your program is slow.
Why are you making a substring? You know how long the string is. You know the index of the letter you are testing. Can't you come up with an equation to calculate the number of substrings? Why do you insist on counting when math is much faster?
If you have a string of length N, how many different substrings can you make that start with string[i]? Present answer in the form of an equation. Instead of solving a simple equation you would rather count from 0 to 9,999 in a loop and then do it again from 1 to 9,999, 1 to 9,999. Now you want to make a substring that is 10,000 characters long, then 9,999 characters long, then 9,998, etc...
No wonder your program is slow.