<p>Given a string <code>s</code>, rearrange the characters of <code>s</code> so that any two adjacent characters are not the same.</p>

<p>Return <em>any possible rearrangement of</em> <code>s</code> <em>or return</em> <code>&quot;&quot;</code> <em>if not possible</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aab"
<strong>Output:</strong> "aba"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "aaab"
<strong>Output:</strong> ""
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 500</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

//greedy algorithm
//we want to prioritize the characters with the most frequency
//once we add a character, we need to keep it out of the heap for one round before we add it back

class Solution {
public:
    string reorganizeString(string s) {
        priority_queue<pair<int, char>> pq;
        unordered_map<char,int> count;

        for(int i = 0; i < s.size(); i++) {
            count[s[i]]++;
        }

        unordered_map<char,int>::iterator it = count.begin();
        while(it != count.end()) {
            pq.push(pair<int,char> {it->second, it->first});
            it++;
        }


        pair<int, char> default_cool = {0, '/0'};
        queue<pair<int,char>> cooldown;
        string ans = "";
        char lastAdded = '/0';

        while(!cooldown.empty() || !pq.empty()) {
            if(!pq.empty()) {
                pair<int,char> most_freq = pq.top();
                pq.pop();

                if(lastAdded == most_freq.second) {
                    return "";
                }

                ans += most_freq.second;
                lastAdded = most_freq.second;
                cout << ans << endl;
                most_freq.first -= 1;

                if(!cooldown.empty()) {
                    pq.push(cooldown.front());
                    cooldown.pop();
                }

                if(most_freq.first != 0) {
                    cooldown.push(most_freq);
                }

            }
            else {
                if(!cooldown.empty()) {
                    pq.push(cooldown.front());
                    cooldown.pop();
                }
            }
            
        }

        return ans;
    }
};
9200