Given a string (may contain both vowel and consonant letters), remove all consonants, then check if the resulting string is palindrome or not.
Examples:
Input : abcuhuvmnba Output : YES Explanation : The consonants in the string "abcuhuvmnba" are removed. Now the string becomes "auua". Input : xayzuezyax Output : NO Input : bkldhgcj Output : -1
Approach:
Remove all the consonants in the string. Check if the vowel string is a palindrome. If it is a palindrome print YES, else print NO. If string contains no vowels, then print -1.
Below is the Python implementation:
# Python program to check if given # string is vowel Palindrome # Function to check if a given string is a vowel def vowel(c): # creating a list of vowels v = list("aeiou") # if the character is a vowel return True if c in v: return True return False # Function to check if a vowel # string is palindrome def palindrome(s): # create a empty list v = [] # append all vowels into the list for i in s: if vowel(i):v.append(i) # if the length of the vowel # string is 0 then print -1 if len(v)== 0: print("-1") # else check if it is a palindrome else: # create a reversed string x = v[::-1] # initialize a flag f = 1 for i in range(len(x)): # if the characters are not the same if x[i]!= v[i]: # set the flag to 0 f = 0 break if f == 1: print("YES") else: print("NO") # Driver Code s = 'abcuhuvmnba' # calling the main function palindrome(s.strip()) |
YES
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.
Recommended Posts:
- Check if the given string is vowel prime
- Python Regex - Program to accept string starting with vowel
- Minimize cost to replace all the vowels of a given String by a single vowel
- Python Program that Extract words starting with Vowel From A list
- Python | Vowel indices in String
- Program to accept Strings starting with a Vowel
- Program to find if a character is vowel or Consonant
- 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
- Replace every vowels with lexicographically next vowel in a String
- Count the nodes of the tree whose weighted string contains a vowel
- Python - Replace vowels by next vowel
- C Program to Check if a Given String is Palindrome
- TCP Client-Server Program to Check if a Given String is Palindrome
- Substrings starting with vowel and ending with consonants and vice versa
- Arrangement of words without changing the relative position of vowel and consonants
- Puzzle | Number of Sheets to be turned so that Prime Number has a Vowel on the other side
- Count of adjacent Vowel Consonant Pairs
- Count of N size strings consisting of at least one vowel and one consonant
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.

