Given a string str consisting of lowercase English alphabets, the task is to count the number of adjacent pairs of vowels.
Input: str = “abaebio”
(a, e) and (i, o) are the only valid pairs.
Input: str = “aeoui”
Approach: Starting from the first character of the string to the second last character, increment count for every character where str[i] as well as str[i + 1] are both vowels. Print the count in the end which is the required count of pairs.
Below is the implementation of the above approach:
# Python3 implementation of the approach
# Function that return true
# if character ch is a vowel
if ch in [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]:
# Function to return the count of adjacent
# vowel pairs in the given string
def vowelPairs(s, n):
cnt = 0
for i in range(n – 1):
# If current character and the
# character after it are both vowels
if (isVowel(s[i]) and
isVowel(s[i + 1])):
cnt += 1
# Driver code
s = “abaebio”
n = len(s)
# This code is contributed
# by mohit kumar
- C++ Program to count Vowels in a string using Pointer
- Program to count vowels in a string (Iterative and Recursive)
- Count the number of vowels occurring in all the substrings of given string
- Python program to count number of vowels using sets in given string
- Program to count vowels, consonant, digits and special characters in string.
- Count number of equal pairs in a string
- Count pairs of characters in a string whose ASCII value difference is K
- Count pairs of non-overlapping palindromic sub-strings of the given string
- Check if a string can be converted to another string by replacing vowels and consonants
- Count substrings that contain all vowels | SET 2
- First X vowels from a string
- Count strings with consonants and vowels at alternate position
- Reverse vowels in a given string
- Modify the string such that it contains all vowels at least once
- Permutations of string such that no two vowels are adjacent
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.