mediumCountingGreedyHash TableHeap Priority QueueSortingString 0 views

Reorganize String

Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

Return any possible rearrangement of s or return "" if not possible.

Reorganize String diagram

Example 1

Input: s = "aab"

Output: "aba"

Example 2

Input: s = "aaab"

Output: ""

Constraints

  • 1 <= s.length <= 500
  • s consists of lowercase English letters.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.