Back to DSA

Reorganize String

medium
Acceptance: 42%
HeapGreedyString

Rearrange the characters of a given string so that no two neighboring characters are identical. If such a rearrangement is impossible, return an empty string.

Examples

Example 1:
Input:s = "bbac"
Output:"babc"
Example 2:
Input:s = "aaaa"
Output:""

Hints

00:00
1234567