Reorganize String
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.

30:00

Reorganize String
medium
Topics
Companies

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.

Example 1:
Input: {"s":"aab"}
Output: aba
Constraints:
  • 1s.length5001 \leq s.\text{length} \leq 500

  • s consists of lowercase English letters.

Input
arr ={"s":"aab"}

Start

Max Heap (Left)

2

1

Min Heap (Right)

Empty

Variables
No variables to display
DepthFunction Call
Stack empty
0/9