Standard Priority Queue IX: Vowels Frequency
Tally the frequency of the vowels. Push that into a pQueue, the caveat is when the frequencies are the same, you need to keep track of the first occurrence of each vowel and do some math to insert into the priority queue with the right order. After that, it is just dequeuing and inserting into the proper places. Use StringBuilder to avoid unnecessary string allocations. Code is down below, cheers, ACC. Sort Vowels by Frequency - LeetCode You are given a string s consisting of lowercase English characters. Rearrange only the vowels in the string so that they appear in non-increasing order of their frequency. If multiple vowels have the same frequency , order them by the position of their first occurrence in s . Return the modified string. Vowels are 'a' , 'e' , 'i' , 'o' , and 'u' . The frequency of a letter is the number of times it occurs in the string. Example 1: Input: ...