Question bank › Arrays
Dsa Arrays Medium

Unique Element Rearrangement

Given an array of integers, determine if it is possible to rearrange the elements such that no two adjacent elements are the same. If possible, return the rearranged array. If not, return an empty array. Input: - The first line contains an integer n (1 <= n <= 1000), the number of elements in the array. - The second line contains n space-separated integers, the elements of the array. Output: - Print the rearranged array as space-separated integers or an empty array if it cannot be rearranged. Example: Input: 6 1 1 2 2 3 3 Output: 1 2 1 2 3 3

Key concepts

arraysrearrangement

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.