Meta Interview Question

Finding the minimum k elements of a list

Interview Answers

Anonymous

Oct 31, 2016

You can use the median of medians k times in order of 0 to k. This will give you O(kn) runtime, this is probably the best solution. Another solution could be to sort and then take the k first elements which give O(nlogn) runtime.

Anonymous

Nov 7, 2016

Well you should maintain a k-size max heap whose top is the kth smallest number in the array. In this way, your time complexity would be only O(nlogk).

Anonymous

Nov 21, 2016

In Java, use a TreeMap.