<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> cnt;
        for (auto x : s)
            cnt[x]++;

        vector<pair<int, char>> freq;
        for (auto x : cnt)
            freq.push_back({x.second, x.first});

        sort(freq.begin(), freq.end(), greater<pair<int, char>>());
        if (freq[0].first > (s.size() + 1) / 2)
            return "";

        string ans = string(s.size(), ' ');
        int idx = 0;
        for (auto x : freq)
        {
            for (int i = 0; i < x.first; i++)
            {
                ans[idx] = x.second;
                idx += 2;
                if (idx >= s.size())
                    idx = 1;
            }
        }

        return ans;
    }
};
8800