Unique Elements Sorter
Given an array of integers, return a sorted array containing the same integers in ascending order, but with all duplicates removed.
[ 3, 1, 2, 3, 4, 1, 2 ]
Explanation. Duplicated integers `1`, `2`, and `3` are removed and the resulting integers are returned in sorted order.
[ -1, -2, 0, 0, 0 ]
Explanation. All occurrences of `0` except one are removed, and the array is sorted in ascending order.
[ 5, 5, 5, 5 ]
Explanation. Only one unique value exists. All duplicates are removed, resulting in a single-element array.
Follow-up: Can you improve your solution to achieve a linear time complexity with the help of additional data structures like a hash table?
The input array may contain both positive and negative integers. The array will at least contain one element. The output array must be sorted in ascending order and must not contain duplicates.
- Views
- 2