Greedy Algorithms8 sections · 316 units
Open in Course

Problem - Reorganize String

No adjacent duplicates

Given a string, rearrange it so no two adjacent characters are the same. Return any valid arrangement or empty string if impossible. For s="aab"s = "aab", return "aba""aba". For s="aaab"s = "aaab", return """" (impossible).

Here's similar to task scheduling.

Think about when rearrangement is possible and what determines the answer.