767. Reorganize String

Practice Reorganize String for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Rearrange the characters of s so that no two neighbouring characters are the same, and return the result. If several rearrangements work, return any of them; the expected value is one of them.

If no such rearrangement exists, return the empty string "".

Example

s = "aab"   ->  "aba"
s = "aaab"  ->  ""

Constraints