0767. Reorganize String

https://leetcode.com/problems/reorganize-string

Description

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 <= 500

  • s consists of lowercase English letters.

ac

It's kinda tricky problem. Maybe solution is not general for other problems.

https://leetcode.com/problems/reorganize-string/discuss/232469/Java-No-Sort-O(N)-0ms-beat-100

Last updated

Was this helpful?