<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) {
        vector<int> mp(26);
        string result = "";
        for(char c : s) {
            mp[c-'a']++;
        }

        priority_queue<vector<int>> pq;
        for(int i=0;i<26;i++) {
            if(mp[i] > 0) {
            cout<<mp[i]<<" "<<char(i+'a')<<endl;
            pq.push(vector<int>{mp[i],i+'a'});
            }
        }

        while(!pq.empty()) {
            vector<int> mostFrequent = pq.top();
            pq.pop();
            result += mostFrequent[1];
            mostFrequent[0]--;
            if(!pq.empty()) {
                vector<int> secondFrequent = pq.top();
                pq.pop();
                result += secondFrequent[1];
                secondFrequent[0]--;
                if(secondFrequent[0] > 0 ) {
                    pq.push(secondFrequent);
                }
            } 
            if(mostFrequent[0] > 0) {
                pq.push(mostFrequent);
            }
            if(pq.size() == 1  && pq.top()[1] == result[result.size()-1]) {
                return "";
            }
        }
        return result;
    }
};
10200