Given a string str of lowercase English alphabets, the task is to check whether the string is a vowel prime or not. A string is said to be vowel prime if all the vowels in the string appear at only prime indices.
Input: str = “geeksforgeeks”
str = ‘e’ is a vowel but 1 is not prime.
Input: str = “bcae”
All the vowels are at prime indices i.e. 2 and 3.
Approach: Use Sieve of Eratosthenes to find all the prime numbers less than N so that every index of the string can be checked for primality. Now, if there is some non-prime index such that the character at that position is a vowel then the string is not vowel prime else it is.
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.
- Python program to check if given string is vowel Palindrome
- Check whether the frequencies of all the characters in a string are prime or not
- Check whether count of distinct characters in a string is Prime or not
- Alternate vowel and consonant string
- Replace every vowels with lexicographically next vowel in a String
- Lexicographically first alternate vowel and consonant string
- Count the nodes of the tree whose weighted string contains a vowel
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Minimize cost to replace all the vowels of a given String by a single vowel
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the sum of prime elements of the array is prime or not
- Check n^2 - m^2 is prime or not
- Check if N is a Factorial Prime
- Check if N is Strong Prime
- Check if a number is Full Prime
- C Program to Check Whether a Number is Prime or not
- Check whether the given numbers are Cousin prime or not
- Check whether the given number is Wagstaff prime or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.