<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) {
        
        unordered_map<char, int> freq;
        priority_queue<pair<int, char>> maxHeap;
        int n = s.size();
        int maxFreq = 0;

        for(char c: s) {
            freq[c]++;
            maxFreq = max(maxFreq, freq[c]);
        }
        
        if(maxFreq > (n + 1) / 2) return "";

        for(const auto& [c, f]: freq) 
            maxHeap.push({f, c});

        string result(n, ' ');
        int i = 0;

        while(!maxHeap.empty()) {
            
            int count = maxHeap.top().first;

            while(count--) {

                result[i] = maxHeap.top().second;
                i += 2;
                if(i >= n) i = 1;
            }

            maxHeap.pop();
        }

        return result;
    }
};
8800