You are a string ‘S’. Your task is to count all the “substrings” of ‘S’ that contain only “vowels”.
Note :1. The string ‘S’ consists of only lowercase English alphabets.
2. A ‘substring’ is a contiguous sequence of characters within a string.
3. Recall that vowels in lowercase English alphabets are: {‘a’, ‘e’, ‘i’, ‘o’, ‘u’}.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the ‘T’ test cases follow.
The first and only line of each test case contains a string ‘S’ of lowercase letters.
Output Format :
For each test case, print in a new line an integer denoting the number of all “substrings” of ‘S’ that contain only “vowels”.
Output for each test case will be printed in a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |S| <= 5000
Time Limit: 1sec
2
codestudio
wxyz
6
0
Test Case 1 :
The substrings that contain only vowels are: {“o”, “e”, “u”, “i”, “io”, “o”}.
Test Case 2 :
There is no substring that contains only vowels.
2
codingninjas
artycg
4
1
Think of generating all substrings, and check each individually.
O(N^3), where ‘N’ is the size of the input string.
To generate all substrings, the time complexity will be O(N^2). After generating a particular substring we are checking whether it contains only vowels or not, which take O(N) more for each time. Hence, the overall time complexity will be O(N^3).
O(N), where ‘N’ is the size of the input string.
As we are generating the substring in the new variable which is of data type string. The size of this string can go up to ‘N’. Hence, the space complexity will be O(N).