O(N^2)
We may loop through all potential substrings of the supplied string and see if they are good strings in this solution. To determine whether a string is good, we can look for at least one vowel and one consonant in the substring.
O(N2) time complexity
Java source code:
[code]```public static int countGoodSubstrings(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
boolean hasVowel = false, hasConsonant = false;
for (int j = i; j < s.length(); j++) {
if (isVowel(s.charAt(j))) {
hasVowel = true;
} else {
hasConsonant = true;
}
if (hasVowel && hasConsonant) {
count++;
}
}
}
return count;
}
public static boolean isVowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}```
[/code]