Rearrange Without Adjacent Equals

PHP Hard 5 views
Back to Questions

Problem Description

Rearrange the string so that no two adjacent characters are the same. If not possible, print IMPOSSIBLE.

Input Format

One line string s (lowercase letters).

Output Format

Rearranged string or IMPOSSIBLE.

Sample Test Case

Input:
aaabbc
Output:
ababac

Constraints

|s|

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev