Given a string S, comprising of only lowercase English alphabets, the task is to update the string by eliminating such vowels from the string that occur between two consonants.
Here the letter ‘a’ is a vowel and is between two immediate consonants.
Thus, it is removed from the string, and the resultant string becomes ‘bb‘
In the substring ‘for’ the alphabet ‘o’ is between two consonants ‘f’ and ‘r’.
Thus, it is removed from there and the string becomes-‘geeksfrgeeks‘
Approach: Initialize an empty updatedString. Given below are the steps to solve the above problem.
- Traverse the string from left to right.
- If the current character is a vowel, check the character before it and the character after it, if both of these are consonants, then the current vowel is a ‘Sandwiched Vowel’ and it needs to be removed from S, thus don’t append this character to A.
Else, append the current character to A.
- Continue the process until all the vowels in between two consonants are removed from the string
Below is the implementation of the above approach:
Time Complexity: O(N) where N is the length of the input string.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Modify the string by swapping continuous vowels or consonants
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Modify the string such that it contains all vowels at least once
- Check if a string can be converted to another string by replacing vowels and consonants
- Replace all consonants with nearest vowels in a string
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- C program to count number of vowels and consonants in a String
- Minimum swaps required to move all vowels occurs after consonants in a given string
- Encrypt string with product of number of vowels and consonants in substring of size k
- Print reverse string after removing vowels
- Check whether all the substrings have number of vowels atleast as that of consonants
- Longest subsequence consisting of alternate vowels and consonants
- Arrange consonants and vowels nodes in a linked list
- Count strings with consonants and vowels at alternate position
- Replace consonants with next immediate consonants alphabetically in a String
- Longest Subsequence of a String containing only Consonants
- Program to remove consonants from a String
- Count consonants in a string (Iterative and recursive methods)
- Minimum cost to modify a string
- Print string after removing all (“10” or “01”) from the binary 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.