246. Sort Them
Foundation1000 ms256 MBSolved by 0%
Print n integers in non-decreasing order.
Write bubble sort first if you have never written one. Then look at the
constraint: n reaches 200000, and bubble sort compares every pair, which is
about twenty billion comparisons. The largest test is sized so it will not
finish.
Use your language's sort, which is O(n log n). The point of this problem is
to feel the difference between the two rather than to learn a new algorithm.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n integers.
Output
Print the n values in non-decreasing order, separated by single spaces.
Input5
3 1 4 1 5
Output1 1 3 4 5
Notehas a repeated value that must appear twice
Input1
7
Output7
Noteis a single element
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution