algorythms
Heap / Priority Queue
LC #767Medium

Reorganize String

Heap / Priority Queue
GoogleAmazonMetaBloomberg

Problem

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

Inputs = "aab"
Output"aba"
Why

"aba" has no two adjacent identical characters

Hints — reveal one at a time