<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) {
        int n = s.size();
        map<char,int> m;
        for(int i=0;i<n;i++){
            m[s[i]]++;
        }
        
        priority_queue<pair<int,char>> q;
        for(auto i : m){
            q.push({i.second, i.first});
        }
        
        string res;
        while(!q.empty()){
            pair<int,char> p = q.top();
            q.pop();
            res+=p.second;
            p.first--;
            if(!q.empty()) {
                pair<int,char> p1 = q.top();
                q.pop();
                res += p1.second;
                p1.first--;
                if(p1.first>0)q.push(p1);
            }
            if(p.first>0) q.push(p);
        }
        
        for(int i=0;i<n-1;i++){
            if(res[i]==res[i+1]) return "";
        }
        return res;
    }
};
9700