Given a string s, count the number of vowels such that both its immediate neighbours are consonants.
A vowel is:
a, e, i, o, u
For a vowel at index i, it should satisfy:
s[i-1] → consonant
s[i] → vowel
s[i+1] → consonant
The first and last characters cannot be counted because they do not have two neighbours.
Input:
s = "abcde"
The vowel e is at the last position, so it has no right neighbour.
The vowel a is at the first position, so it has no left neighbour.
Output:
0
Input:
s = "bat"
a has:
left = b → consonant
right = t → consonant
Therefore:
Output:
1
Input:
s = "banana"
For every a:
b a n → valid
n a n → valid
n a → no right neighbour
Therefore:
Output:
2
1 ≤ |s| ≤ 10^5
Note: Assume the string contains English alphabetic characters. Case-insensitive vowel checking may be used if uppercase letters are allowed.
Schlumbergera • Pending
Schlumbergera • Pending
Willingness • Pending
Willingness • Pending