Given a string, the task is to count the number of adjacent pairs such that the first element of the pair is a consonant and the second element is a vowel. That is find the number of pairs (i, i+1) such that the ith character of this string is a consonant and the (i+1)th character is a vowel.
Input : str = "bazeci" Output : 3 Input : str = "abu" Output : 1
- We have to find all possible adjacent consonant-vowel pairs.
- Insert all of the vowels in a set or hash, so that we can check if the current character is a vowel or consonant in constant time.
- We run a loop for the first n-1 elements and check, if the ith character is a consonant, and the (i+1)th character a vowel or not.
- If so, we increment the count, else we continue till the end of the string.
Below is the implementation of the above approach:
Time Complexity: O(N), where N is the length of the string.
Auxiliary Space: O(1). We have used additional space to store vowels in a Hash but since number of vowels is only 5 so, the extra space used is considered as constant.
- Alternate vowel and consonant string
- Program to find if a character is vowel or Consonant
- Lexicographically first alternate vowel and consonant string
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Program to count vowels, consonant, digits and special characters in string.
- Count the nodes of the tree whose weighted string contains a vowel
- Remove first adjacent pairs of similar characters until possible
- Count of strings where adjacent characters are of difference one
- Count non-adjacent subsets from numbers arranged in Circular fashion
- Count pairs (i,j) such that (i+j) is divisible by A and B both
- Count the pairs of vowels in the given string
- Count of pairs of strings which differ in exactly one position
- Count pairs of strings that satisfy the given conditions
- Count number of equal pairs in a string
- Count pairs of non-overlapping palindromic sub-strings of the given string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.