CSES Problemset/Introductory Problems
String Reorder
#1743Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude DesktopYour task is to reorder the characters of a string so that no two adjacent characters are the same. What is the lexicographically minimal such string?
Input
The only line has a string of length consisting of characters A–Z.
Output
Print the lexicographically minimal reordered string where no two adjacent characters are the same. If it is not possible to create such a string, print .
Constraints
Sample Test Cases (1)
Example 1ID: sample-1
Input
HATTIVATTI
Expected Output
AHATITITVT
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 charsTest Bench
Input (stdin)
HATTIVATTI
Expected Output
AHATITITVT