36. Sort an Array of Unknown Size
Difficulty: easy · Array, Sorting
Problem
You are given a list of integers on a single line, but the number of integers is **not** given. Read all of them and print them sorted in descending order.
Input
A single line containing one or more integers separated by single spaces.
Output
Print the integers in descending order on one line, separated by single spaces.
Example 1
Input: 3 1 4 1 5 9 2 6 Output: 9 6 5 4 3 2 1 1
Explanation: Sorted from largest to smallest: 9 6 5 4 3 2 1 1.
Example 2
Input: -2 -7 0 Output: 0 -2 -7
Explanation: 0 is largest, then -2, then -7.
Constraints
- 1 <= number of integers <= 10^5 - -10^9 <= each integer <= 10^9
Solutions are judged against 2 sample and 8 hidden tests. Sign in to solve it · All problems