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

typedef pair<int,char> p;
class Solution {
public:
    string reorganizeString(string s) {
        priority_queue<p>pq;
        vector<int>alp(26,0);
        for(char ch:s){
            alp[ch-'a']++;
        }
        for(int i=0;i<=25;i++){
            if(alp[i]!=0){
                pq.push({alp[i],'a'+i});
            }
        }
        string ans;
        while(pq.size()>1){
            auto first=pq.top();
            pq.pop();
            auto second=pq.top();
            pq.pop();
            if(ans.size()!=0&&ans.back()==first.second){
                swap(first,second);
            }
            ans.push_back(first.second);
            ans.push_back(second.second);
            if(first.first-1!=0)
                pq.push({first.first-1,first.second});
            if(second.first-1!=0)
                pq.push({second.first-1,second.second});

        }
        if(pq.size()==0) return ans;
        if(pq.size()==1&&pq.top().first==1) {
            ans.push_back(pq.top().second);
            return ans;
        } 
        return "";
       

    }
};
8000