JAVA/PYTHON/C++ || (100%) 43ms time/space || Counting Sort ||
Intuition\nTo solve this problem, we need to sort the vowels in the input string while keeping the consonants in their original positions. The approach involves
# Intuition\nTo solve this problem, we need to sort the vowels in the input string while keeping the consonants in their original positions. The approach involves extracting the vowels from the string, sorting them, and then placing them back in their respective positions in the original string.\n\n# Approach\n1. Create a `StringBuilder` to easily modify characters in the string.\n2. Extract the vowels from the input string and store them in a list.\n3. Sort the list of vowels based on their ASCII values using counting sort.\n4. Iterate over the input string, and whenever we encounter a vowel, replace it with the next element from the sorted list of vowels.\n5. Convert the modified `StringBuilder` back to a string and return the result.\n\n# Complexity\n- Time complexity: O(N), where N is the length of the input string `s`. The counting sort takes linear time as we process each character in the string.\n- Space complexity: O(N), due to the creation of the `list` array to store the vowels.\n\n# Java Code\n```java\nclass Solution {\n    public String sortVowels(String s) {\n        StringBuilder sb = new StringBuilder(s);\n        ArrayList<Character> list = new ArrayList<>();\n        for(char c : s.toCharArray()){\n            if(isVowel(c))\n                list.add(c);\n        }\n        countingSort(list);\n        int idx = 0;\n        for(int i = 0; i < s.length(); i++){\n            if(isVowel(sb.charAt(i)))\n                sb.setCharAt(i, list.get(idx++));\n        }\n        return sb.toString();\n    }\n\n    public static boolean isVowel(char letter) {\n        char lowercaseLetter = Character.toLowerCase(letter);\n        switch (lowercaseLetter) {\n            case \'a\':\n            case \'e\':\n            case \'i\':\n            case \'o\':\n            case \'u\':\n                return true;\n            default:\n                return false;\n        }\n    }\n\n    public static void countingSort(List<Character> list) {\n        int n = list.size();\n        char[] output = new char[n];\n        int[] count = new int[256];\n        for (char c : list) {\n            count[c]++;\n        }\n        int j = 0;\n        for (int i = 0; i < 256; i++) {\n            while (count[i] > 0) {\n                output[j] = (char) i;\n                count[i]--;\n                j++;\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            list.set(i, output[i]);\n        }\n    }\n}\n```\n\n# Python Code\n```python\nclass Solution:\n    def sortVowels(self, s: str) -> str:\n        vowels = [c for c in s if self.isVowel(c)]\n        vowels.sort()\n        idx = 0\n        result = \'\'\n        for c in s:\n            if self.isVowel(c):\n                result += vowels[idx]\n                idx += 1\n            else:\n                result += c\n        return result\n\n    def isVowel(self, letter: str) -> bool:\n        lowercase_letter = letter.lower()\n        return lowercase_letter in {\'a\', \'e\', \'i\', \'o\', \'u\'}\n```\n\n# C++ Code\n```cpp\nclass Solution {\npublic:\n    string sortVowels(string s) {\n        vector<char> vowels;\n        for (char c : s) {\n            if (isVowel(c))\n                vowels.push_back(c);\n        }\n        sort(vowels.begin(), vowels.end());\n        int idx = 0;\n        for (char &c : s) {\n            if (isVowel(c))\n                c = vowels[idx++];\n        }\n        return s;\n    }\n\n    bool isVowel(char letter) {\n        char lowercaseLetter = tolower(letter);\n        return lowercaseLetter == \'a\' || lowercaseLetter == \'e\' || lowercaseLetter == \'i\' ||\n               lowercaseLetter == \'o\' || lowercaseLetter == \'u\';\n    }\n};\n```\nfeel free to ask any questions
['String', 'Counting Sort', 'C++', 'Java', 'Python3']