Use an Ordered Hash Map to Sort + Tally the Vowels - JavaScript, O(n)
Approach\nTo avoid sorting the string\'s vowels with an O(n^2) method, I created a hash map vowelMap to store tallies of the 5 vowels in upper and lowercase. I 
# Approach\nTo avoid sorting the string\'s vowels with an O(n^2) method, I created a hash map `vowelMap` to store tallies of the 5 vowels in upper and lowercase. I intentionally ordered the vowel keys by their ASCII values (uppercase first + alphabetical order). That way, when iterating over the map later, the vowels can be pulled in sorted order.\n\nSo, I then iterated over `s`, increasing the tallies of each vowel when found. \n\nI then iterated over `vowelMap` to assemble a string of the vowels `sortedVowels`. Because the hash map is pre-ordered, the vowels are added in sorted order.\n\nLast, I iterated over `s` again to assemble an output string `newStr`, using `vowelMap` to check each character. If it\'s a vowel, I added the `i`th character from `sortedVowels` to `newStr`. If it\'s a consonant, I just added that to `newStr`.\n\n# Complexity\n### Time complexity: O(n) \nSimplified from **O(3n)**\nBeats 99.21% on Nov 13, 2023\n\n- I iterate over `s` twice, so O(2n) with `n` being the length of `s`. \n- I also iterate over `vowelMap` once: O(10) for the 10 vowels. But I use `.repeat()` to add multiple copies of the same vowel to `sortedVowels`. My assumption is that there is an operation completed for each repetition within the `.repeat()` method, so this would also take O(n) time.\n\n### Space complexity: O(n)\nSimplified from **O(2n + 10)**\nBeats 97.64% on Nov 13, 2023\n\n- I need `n` space for the output string with `n` being the length of `s`. \n- I also need `n` space for `sortedVowels` because `s` could potentially only include vowels.\n- The `vowelMap` requires O(10) space to store each vowel\'s tally.\n\n# Code\n```\n/**\n * @param {string} s\n * @return {string}\n */\nvar sortVowels = function(s) {\n    const vowelMap = {\n        \'A\': 0, \'E\': 0, \'I\': 0, \'O\': 0, \'U\': 0,\n        \'a\': 0, \'e\': 0, \'i\': 0, \'o\': 0, \'u\': 0\n    }\n    for (let char of s) {\n        if (vowelMap[char] !== undefined) vowelMap[char]++ \n    }\n    let sortedVowels = \'\'\n    for (let vowel in vowelMap) {\n        if (vowelMap[vowel]) {\n            sortedVowels += vowel.repeat(vowelMap[vowel])\n        }\n    }\n    let newStr = \'\'\n    let i = 0\n    for (let char of s) {\n        if (vowelMap[char]) newStr += sortedVowels[i++]\n        else newStr += char\n    }\n    return newStr\n};\n```
['Hash Table', 'String', 'JavaScript']