Heap / Priority Queue
LC #767Medium
Reorganize String
Heap / Priority Queue
GoogleAmazonMetaBloombergProblem
Rearrange characters in a string so no two adjacent characters are the same. Return "" if impossible.
stringheapgreedyhash-map
Constraints
- ›1 ≤ s.length ≤ 500
- ›s consists of lowercase English letters
Example
Input
s = "aab"Output
"aba"Why
"aba" has no two adjacent identical characters