<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) {
        auto comp = [](std::pair<char, int>& a, std::pair<char, int>& b){
            return b.second > a.second;
        };
        priority_queue<std::pair<char, int>, std::vector<std::pair<char, int>>, decltype(comp)>  pq (comp);
        std::map<char, int> m;
        for (int i = 0; i<s.size(); i++) {
            int& a = m[s.at(i)];
            a++;
        }
        for (const auto& [key, value] : m) {
            pq.push({key, value});
        }
        string r;
        char last_one = ' ';
        while (!pq.empty()) {
            auto p = pq.top();
            pq.pop();
            if (p.first == last_one) {
                if (pq.empty())
                    return "";
                auto p2 = pq.top();
                pq.pop();
                r += p2.first;
                p2.second--;
                if (p2.second >0) pq.push(p2);
                pq.push(p);
                last_one = p2.first;
                continue;
            }

            r+=p.first;
            p.second--;
            last_one = p.first;
            if (p.second > 0) pq.push(p);
         }
         return r;
    }
};
10000