Dsa
Sorting
Easy
The Odd-Even Library
A librarian wants to reorder a list of book ID numbers. All even-numbered IDs must appear first, sorted in ascending order. Following all even IDs, all odd-numbered IDs must appear, sorted in descending order.
Input Format:
Line 1: An integer N.
Line 2: N space-separated integers representing book IDs.
Output Format:
A single line of space-separated integers in the required order.
Example:
Input:
5
1 2 3 4 5
Output:
2 4 5 3 1
Key concepts
parityconditional logic
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