Reorganize String Problem
Reorganize String Problem — ExecCode Medium DSA Practice
Solve the Reorganize String problem on ExecCode. Free online medium DSA practice in Greedy. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a string s, rearrange the characters of s so that no two adjacent characters are the same, and return any valid rearrangement. If it is not possible to rearrange s this way, return an empty string.
Examples
Input s = "aab"; Output "aba". Input s = "vvvlo"; Output "vlvov". Input s = "aaab"; Output ""
Constraints
1 ≤ s.length ≤ 500 s consists of lowercase English letters
Practice Reorganize String free on ExecCode. Browse DSA problems, topic map, and placement guides.