Reorganize String
Given a string s, rearrange its characters so that no two adjacent characters are the same. Return any valid rearrangement, or an empty string if it is impossible.
Open official problem prompt ↗Produce an ordering of the characters where equal characters never touch, or prove none exists.
Seating guests who dislike their duplicates side by side: always seat the largest remaining group first, but never let a group take two seats in a row — make it wait one seat before it can be seated again.
- Input
- s = "aab"
- Output
- "aba"
- Why
- The two a's are separated by the single b, so no two adjacent characters match.
1 <= s.length <= 500s consists of lowercase English letters