No two neighbours alike

Write rearrange(text) that returns a rearrangement of the characters of text in which no two adjacent characters are the same, or "" if that is impossible. Any valid arrangement passes.

rearrange("aab")   ->  "aba"
rearrange("aaab")  ->  ""
rearrange("aabb")  ->  "abab"  or "baba"

The point is to practise a max-heap by count: always place the most frequent remaining character, but never the one you just placed.

def rearrange(text):
    ...