767. Reorganize String
Medium56.8% acceptance583,422 / 1,026,339 submissions
Asked by 24 companies
Topics
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"
Example 2:
Input: s = "aaab" Output: ""
Constraints:
1 <= s.length <= 500sconsists of lowercase English letters.
Hints
Hint 1
Alternate placing the most common letters.