Sorting Vowels in a String
Intuition\nThe main idea is to isolate the vowels from the given string, sort them, and then reinsert them back into their original positions. This ensures that
# Intuition\nThe main idea is to isolate the vowels from the given string, sort them, and then reinsert them back into their original positions. This ensures that all vowels in the string are sorted while non-vowel characters remain in their original positions.\n\n# Approach\n1. Extract Vowels: Iterate through the given string and extract all vowels into a separate array. Simultaneously, create a modified string where each vowel is replaced with a placeholder (e.g., \'+\').\n2. Sort Vowels: Sort the array of extracted vowels in descending order.\n3. Reinsert Vowels: Iterate through the modified string and replace each placeholder with the next vowel from the sorted array.\n\n# Complexity\n- Time complexity:\nO(nlogn).\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string sortVowels(string s) {\n        string s_modify="";\n        vector<char> arr;\n        for(char element : s)\n        {\n            if(element==\'A\' || element==\'E\' || element==\'I\' || element==\'O\' || element==\'U\' || element==\'a\' || element==\'e\' || element==\'i\' || element==\'o\' || element==\'u\')\n            {\n                s_modify += \'+\';\n                arr.push_back(element);\n            }\n            else\n            {\n                s_modify += element;\n            }\n        }\n\n        std::sort(arr.begin(), arr.end());\n        std::reverse(arr.begin(), arr.end());\n\n        for(int i=0; i<s_modify.length(); i++)\n        {\n            if(s_modify[i]==\'+\')\n            {\n                s_modify[i]=arr.back();\n                arr.pop_back();\n            }\n        }\n\n        return s_modify;\n    }\n};\n```
['C++']