Dashboard
LC #767

Reorganize String

Pattern · ?GoogleAmazonMetaBloomberg

Problem

Rearrange characters in a string so no two adjacent characters are the same. Return "" if impossible.

Constraints

  • 1 ≤ s.length ≤ 500
  • s consists of lowercase English letters

Example

Input
s = "aab"
Output
"aba"
Why
"aba" has no two adjacent identical characters

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗