Given string str of size N, which contains lowercase English alphabets. The task is to replace each vowel with the next immediate vowel lexicographically, i.e.,
‘a’ will be replaced by ‘e’,
‘e’ will be replaced by ‘i’,
‘i’ will be replaced by ‘o’,
‘o’ will be replaced by ‘u’,
‘u’ will be replaced by ‘a’.
Input: str = “geeksforgeeks”
e is replace by i
o is replace by u
So final string will be “giiksfurgiiks”.
Input: str = “gfg”
Approach: We will create a Hashing of size 5 to store all vowels so that the replacement can be done easily for each vowel.
- Create a map and store all vowels.
- Iterate the string elements from left to right.
- It the string element is a vowel, then change it to the next vowels.
- Finally, print the final string.
Here is the implementation of the above approach:
Time Complexity: O (N)
Auxiliary Space: O (1)
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.
- Minimize cost to replace all the vowels of a given String by a single vowel
- Lexicographically first alternate vowel and consonant string
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every array element by multiplication of previous and next
- Replace every array element by sum of previous and next
- Replace every array element by Bitwise Xor of previous and next element
- Replace every element of the array by its next element
- Replace every element in a circular array by sum of next K elements
- Count pair of strings whose concatenation has every vowel
- Replace all consonants with nearest vowels in a string
- Lexicographically next string
- Lexicographically next greater string using same character set
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Lexicographically smallest K-length substring containing maximum number of vowels
- Replace consonants with next immediate consonants alphabetically in a String
- Lexicographically next permutation in C++
- Alternate vowel and consonant string
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Python program to check if given string is vowel Palindrome
- Count the nodes of the tree whose weighted string contains a vowel
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.