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
- Alternate vowel and consonant string
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Lexicographically first alternate vowel and consonant string
- Count the nodes of the tree whose weighted string contains a vowel
- Replace every vowels with lexicographically next vowel in a String
- Program to find if a character is vowel or Consonant
- Arrangement of words without changing the relative position of vowel and consonants
- Count of adjacent Vowel Consonant Pairs
- Count pair of strings whose concatenation has every vowel
- Count of N size strings consisting of at least one vowel and one consonant
- 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 if a number is Prime, Semi-Prime or Composite for very large numbers
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Count all prime numbers in a given range whose sum of digits is also prime
- Check whether count of distinct characters in a string is Prime or not
- Check whether the frequencies of all the characters in a string are prime or not
- Find coordinates of a prime number in a Prime Spiral
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.