Reorganize String

Given a string s, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.

If possible, output any possible result. If not possible, return the empty string.

Example 1:

Input:s = "aab"

Output: aba

Example 2:

Input:s = "aaab"

Output: ``

Note:

s will consist of lowercase letters and have length in the range [1, 500].

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro