<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) {
        map <char, int> mp;
        for(char ch:s) mp[ch]++;
        priority_queue <pair<int,char>> pq;
        for(auto i:mp) pq.push({i.second, i.first});
        string ans = "";
        while(!pq.empty())
        {
            if(pq.size()==1)
            {
                pair <int, char> p = pq.top(); pq.pop();
                if(p.first>1) return "";
                ans += p.second;
            }
            else
            {
                pair <int, char> p1 = pq.top(); pq.pop();
                pair <int, char> p2 = pq.top(); pq.pop();
                ans += p1.second;
                ans += p2.second;
                if(p1.first>1) pq.push({p1.first-1,p1.second});
                if(p2.first>1) pq.push({p2.first-1,p2.second});
            }
        }

        return ans;

    }
};
9300