<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>

"""
ip = "aab"
op = "aba"

ip: "aaab"
op: ""

ip: "a"
op: "a"

ip: "aaaa"
op: ""

ip: "abcd"
op: "abcd"

ip: "aabbb"
op: "babab"

ip: "aabbbc"
op: "bababc"

Brute Force: 3 pointers is not possible

ip: ababcb

ip: ababcbb -> bababcb

Having a counter:
- create a counter
- sort the keys as per the counter
- read the counter 1 by 1 into a result string?

ip: ababcbb -> {a:2, b:4, c:1} -> {b:4, a:2, c:1}
bababcb

ip: abbacc -> {a:2, b:2, c:2} -> abcabc

"""
class Solution:
    def reorganizeString(self, s: str) -> str:        
        ans = []
        # Min heap ordered by character counts, so we will use
        # negative values for count
        pq = [(-count, char) for char, count in Counter(s).items()]
        heapify(pq)

        while pq:
            count_first, char_first = heappop(pq)
            if not ans or char_first != ans[-1]:
                ans.append(char_first)
                if count_first + 1 != 0: 
                    heappush(pq, (count_first + 1, char_first))
            else:
                if not pq: return ''
                count_second, char_second = heappop(pq)
                ans.append(char_second)
                if count_second + 1 != 0:
                    heappush(pq, (count_second + 1, char_second))
                heappush(pq, (count_first, char_first))

        return ''.join(ans)
        
16400