<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) {
        int arr[26] = {0};
        int n = s.size();
        int mostCountChar = 0;
        for (char c : s) {
            arr[c - 'a']++;
            if (arr[c - 'a'] > arr[mostCountChar])
                mostCountChar = c - 'a';
        }

        if (arr[mostCountChar] > (n + 1) / 2) return "";

        int i = 0;
        while (arr[mostCountChar] != 0) {
            s[i] = 'a' + mostCountChar;
            i += 2;
            arr[mostCountChar]--;
        }

        for (int j = 0; j < 26; j++) {
            while (arr[j]) {
                if (i >= n) 
                    i = 1;
                s[i] = 'a' + j;
                arr[j]--;
                i += 2;
            }
        }
        return s;
    }
};
7700