Given a string which contains lowercase English alphabets. The task is to replace each consonant with the next immediate consonant that comes in English alphabets.
Let’s say we have to replace character , it will be replaced by . Another example, let’s say we have to replace character , the next immediate consonant is , hence will be replaced by .
Note: If the character is ‘z’, then look circularly in English alphabets for the next consonant, i.e. replace it with ‘b’.
Input : str = "geeksforgeeks" Output : heeltgosheelt Input : str = "gfg" Output : hgh
- Iterate the string elements from left to right.
- It the string element is consonant, then check the next immediate alphabet of this element.
- If the next immediate alphabet is a consonant, then replace it with the this alphabet. If it is a vowel, then replace the string element with 2nd immediate alphabet as there are no consecutive vowels in English alphabets.
Below is the implementation of the above program:
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.
- Find a string such that every character is lexicographically greater than its immediate next character
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Replace all consonants with nearest vowels in a string
- Minimize cost to empty a given string by removing characters alphabetically
- Sort an Array alphabetically when each number is converted into words
- Replace every vowels with lexicographically next vowel in a String
- Check if a string can be converted to another string by replacing vowels and consonants
- Encrypt string with product of number of vowels and consonants in substring of size k
- Count consonants in a string (Iterative and recursive methods)
- Modify string by removing vowels in between two consonants
- Program to remove consonants from a String
- Modify the string by swapping continuous vowels or consonants
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Longest Subsequence of a String containing only Consonants
- Minimum swaps required to move all vowels occurs after consonants in a given string
- Arrange consonants and vowels nodes in a linked list
- Substrings starting with vowel and ending with consonants and vice versa
- Count strings with consonants and vowels at alternate position
- Arrangement of words without changing the relative position of vowel and consonants
- Check whether all the substrings have number of vowels atleast as that of consonants