Sort the Array
Easy · rating 1050 · Sorting, Arrays
The first line contains n. The second line contains n space-separated integers. Print them sorted in non-decreasing order, space-separated on one line.
Constraints: 1 ≤ n ≤ 105
Editorial
Sort the Array asks you to output the integers in non-decreasing order — a direct use of your language's built-in sort.
Note
Library sorts (Timsort, introsort) are O(n log n) and heavily optimized; hand-rolling a sort is rarely worthwhile outside of learning the algorithms themselves.
nums.sort()
print(*nums)Complexity
Time: O(n log n). Space: O(n) or O(1) depending on the sort.
Related problems
- Merge Two Sorted Arrays — Easy
- Kth Largest Element — Medium
- Median Value — Medium
- Search Insert Position — Medium
- Account Balance — Easy
- Best Time to Buy and Sell Stock — Easy