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:
Time Complexity: O(n) Here, n is the length of string.
- Check if a string can be converted to another string by replacing vowels and consonants
- Modify the string such that it contains all vowels at least once
- Reverse vowels in a given string
- Permutations of string such that no two vowels are adjacent
- Remove consecutive vowels from string
- Program to remove vowels from a String
- Modify string by removing vowels in between two consonants
- Replace all consonants with nearest vowels in a string
- Check whether the vowels in a string are in alphabetical order or not
- Print reverse string after removing vowels
- Modify the string by swapping continuous vowels or consonants
- Count the number of vowels occurring in all the substrings of given string
- Program to count vowels in a string (Iterative and Recursive)
- 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
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.