← Practice problem bank

Jun 6, 2026

Library Book Sorter

Daily Challenge Archive · Open

easysorting

100 pts · 10000 ms · 128 MB · Practice only

Problem

As the new virtual librarian, your job is to sort the books in the library. The books are represented by a list of unique IDs, ranging from 1 to n. Unfortunately, the books are not in order. Your task is to write a program that will sort the books by their IDs in ascending order. For example, if you are given the list [5, 3, 1, 4, 2], your program should return [1, 2, 3, 4, 5].

Hints
You can use any sorting algorithm you like, but some algorithms are more efficient than others. Remember, your solution will be tested against multiple test cases, so make sure your output matches exactly.

Input format

The input consists of a single line containing n space-separated integers representing the book IDs. The IDs are given in no particular order. (1 ≤ n ≤ 10^6)

Output format

The output should be a single line containing n space-separated integers representing the sorted book IDs in ascending order. Make sure there is no trailing space at the end of the line.

Constraints

All book IDs are unique and range from 1 to n inclusive.

Sample input

5 3 1 4 2

Sample output

1 2 3 4 5

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in