Suppose we have a string s. We have to check whether the vowels present in s are in alphabetical order or not.
So, if the input is like s = "helloyou", then the output will be True as vowels are e, o, o, u all are in alphabetical order.
To solve this, we will follow these steps −
- character := character whose ASCII is 64
- for i in range 0 to size of s - 1, do
- if s[i] is any one of ('A','E','I','O','U','a','e','i','o','u'), then
- if s[i] < character, then
- return False
- otherwise,
- character := s[i]
- if s[i] < character, then
- if s[i] is any one of ('A','E','I','O','U','a','e','i','o','u'), then
- return True
Let us see the following implementation to get better understanding −
Example Code
def solve(s): character = chr(64) for i in range(len(s)): if s[i] in ['A','E','I','O','U','a','e','i','o','u']: if s[i] < character: return False else: character = s[i] return True s = "helloyou" print(solve(s))
Input
"helloyou"
Output
True