<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>

class Solution {
public:
    string reorganizeString(string s) {
        unordered_map<char, int> m;
        for (int i = 0; i < s.size(); i++) {
            m[s[i]]++;
        }
        priority_queue<pair<int, char>> pq;
        
        for(auto itr=m.begin(); itr != m.end(); itr++){
            pq.push({itr->second, itr->first});
        }

        int size = s.size();
        int x = 0;

        while(!pq.empty()){
            auto top = pq.top();
            pq.pop();
            int freq = top.first;
            char character = top.second;
            if(freq > (size+1)/2) return "";
            while(freq!=0){
                freq--;
                if(x>=size) x=1;
                s[x]=character;
                x=x+2;
            }
        }
        return s;
    }
};
8400