Given a string str. The task is to modify the string by swapping two adjacent characters if both of them are vowels or both of them are consonants.
Input: str = “geeksforgeeks”
The alphabets ‘e’ and ‘e’ in geeksforgeeks are vowels so they are swapped so the string becomes geeksforgeeks.
The alphabets ‘k’ and ‘s’ in geeksforgeeks are consonants so they are swapped so the string becomes geeskforgeeks.
The alphabets ‘k’ and ‘f’ in geeskforgeeks are consonants so they are swapped so the string becomes geesfkorgeeks.
The alphabets ‘r’ and ‘g’ in geesfkorgeeks are consonants so they are swapped so the string becomes geeskfogreeks.
The alphabets ‘e’ and ‘e’ in geeskfogreeks are vowels so they are swapped so the string becomes geeskfogreeks.
The alphabets ‘k’ and ‘s’ in geeskfogreeks are vowels so they are swapped so the string becomes geeskfogreesk.
Input:str = “gefeg”
No continous vowels or consonants.
- Traverse through the characters in the string.
- Consider the current character and the next character.
- If both the characters are consonants or both the characters are vowels.
- Then swap the characters.
- Else continue the process till the end of the string.
Below is the implementation of the above approach:
- Modify string by removing vowels in between two 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
- Encrypt string with product of number of vowels and consonants in substring of size k
- 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
- Program to remove consonants from a String
- Minimum cost to modify a string
- Count consonants in a string (Iterative and recursive methods)
- First X vowels from a string
- Reverse vowels in a given string
- Count the pairs of vowels in 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.