Skip to content

Practice Reorganize String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#767
LeetCode Problem

Reorganize String

Problem Statement

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.

Source: Reorganize String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aab"
Output
"aba"

# Example 2

Input
s = "aaab"
Output
""

Constraints

1 <= s.length <= 500
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Reorganize String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.