Given a string containing only english alphabets, the task is to print the longest subsequence containing only consonants.
Input : str = “geeksforgeeks”
Output : gksfrgks
The longest subsequence containing consonants will be the string of all the consonants in the given string.
Here, it is given by the string “gksfrgks”.
Input : str = “HelloWorld”
Output : HllWrld
- First, we will traverse through the given string.
- We will include all the consonants that we encounter during our traversal into the answer string.
- Once the entire initial string has been encountered, we have the longest subsequence containing only consonants with us.
Below is the implementation of the above approach:
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.
- Longest Subsequence of a String containing only vowels
- Replace consonants with next immediate consonants alphabetically in a String
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Longest subsequence consisting of alternate vowels and consonants
- Length of longest common subsequence containing vowels
- Count of substrings of a Binary string containing only 1s
- Longest Substring having equal count of Vowels and Consonants
- Longest Consecuetive Subsequence when only one insert operation is allowed
- Check if a string can be converted to another string by replacing vowels and consonants
- Longest subsequence such that every element in the subsequence is formed by multiplying previous element with a prime
- Find length of longest subsequence of one string which is substring of another string
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Count of Subsets containing only the given value K
- Count of substrings containing only the given character
- 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
- Replace all consonants with nearest vowels in a string
- Program to remove consonants from a String
- Modify the string by swapping continuous vowels or consonants
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.