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
- Remove consecutive vowels from string
- Program to duplicate Vowels in String
- Program to remove vowels from a String
- Count the pairs of vowels in the given string
- Permutations of string such that no two vowels are adjacent
- Print reverse string after removing vowels
- Check whether the vowels in a string are in alphabetical order or not
- Modify string by removing vowels in between two consonants
- Replace all consonants with nearest vowels in a string
- Count the number of vowels occurring in all the substrings of given string
- Program to count vowels in a string (Iterative and Recursive)
- Queries to find the count of vowels in the substrings of the given string
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.