Dsa
Strings
Warm-up
String Character Rearrangement
Given a string, rearrange its characters in such a way that no two adjacent characters are the same. If rearrangement is not possible, return an empty string.
Input:
- A single line containing the input string.
Output:
- The rearranged string or an empty string if it's not possible.
Example:
Input:
"aab"
Output:
"aba"
Key concepts
stringsmanipulationsorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now