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())
Output:
YES
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.