Given a string str and an integer X, the task is to find and print first X vowels from str. If total vowels in str is < X then print -1.
Input: str = “GeeksForGeeks”, X = 3
‘e’, ‘e’ and ‘o’ are the first three vowels in the given string.
Input: str = “softcopy”, X = 5
Total vowel count is 2 i.e ‘o’ and ‘o’
Approach: Traverse the string character by character and check if the current character is a vowel. If current character is a vowel then concatenate it to the resultant string, result. If at any point the length of the resultant string becomes X then print the string result else print -1 in the end.
Below is the implementation of the above approach:
- Reverse vowels in a given string
- Modify the string such that it contains all vowels at least once
- Program to remove vowels from a String
- Permutations of string such that no two vowels are adjacent
- Remove consecutive vowels from string
- Replace all consonants with nearest vowels in a string
- Modify string by removing vowels in between two consonants
- Print reverse string after removing vowels
- Check whether the vowels in a string are in alphabetical order or not
- Program to count vowels in a string (Iterative and Recursive)
- Count the number of vowels occurring in all the substrings of given string
- Python program to count number of vowels using sets in given string
- Encrypt string with product of number of vowels and consonants in substring of size k
- Program to count vowels, consonant, digits and special characters in string.
- Longest substring of vowels
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.