We iterate over the input string and keep track of all indices and their vowels. Then we sort them lexicographically so that characters with lower ASCII are ordered first than their counterparts with greater ASCII.
Then we iterate over the string again and when we come across vowels, we fetch from our sorted list of vowels.
Code:
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are using sort.
-
Memory
The memory usage is since we use a dictionary to store indices from input string, which would be of length .
— A