Find the kth smallest numbers in an unsorted integer array.
Example
Given[3, 4, 1, 2, 5], k =3, the 3rd smallest numbers are[1, 2, 3].
[3, 4, 1, 2, 5]
3
[1, 2, 3]
Challengearrow-up-right
An O(nlogn) algorithm is acceptable, if you can do it in O(n), that would be great.
Version 1: BruteForce O(nlogn)
Sort the array, return array[k-1];
Version 2: QuickSort
Last updated 5 years ago