![]() |
VOOZH | about |
Given a string 'str', the task is to find whether the vowels in the string are in alphabetical order or not. The string contains only lowercase alphabets.
Examples:
Input: str = "aabbbddeecc" Output: Vowels are in alphabetical order The vowel characters in the string are : a, a, e, e which are in sorted order. Input: str = "aabbbdideecc" Output: Vowels are not in alphabetical order
Approach:
Below is the implementation of the above approach:
Yes
Complexity Analysis:
Approach 2: Using Stack:
We can also solve this problem using a stack data structure in C++. We can push the vowel characters encountered onto the stack as we iterate through the string. If we encounter a new vowel character that is smaller than the top of the stack, we know that the vowels are not in alphabetical order. Otherwise, we continue iterating and pushing onto the stack. If we reach the end of the string without finding any violations, we know that the vowels are in alphabetical order.
Here's the code using a stack:
Output
Yes
Complexity Analysis:
Time Complexity: O(N), where N is the size of the string
Auxiliary Space: O(N) For Stacks