<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) {
        string ans = "";
        map<int,int> mpp;
        for(int i =0;i<s.size();i++)    mpp[s[i]]++;
        vector<pair<int,char>> vec;
        for(auto it:mpp)    vec.push_back(make_pair(it.second,it.first));
        sort(vec.begin(),vec.end(),greater<pair<int,char>>());
        ans+=vec[0].second;
        if(vec[0].first>0)  vec[0].first--;
        for(int i =1;i<s.size();i++){
            sort(vec.begin(),vec.end(),greater<pair<int,char>>());
            if(ans[i-1]!=vec[0].second){
                ans.push_back(vec[0].second);
                vec[0].first--;
            }
            else{
                if(vec.size()==1 || vec[1].first<=0)    return "";
                else{
                    ans.push_back(vec[1].second);
                    vec[1].first--;
                }
            }
        }
        return ans;
    }
};
9600