Find K-th largest element in an array.
You can swap elements in the array
Have you met this question in a real interview?
Yes
Example
In array[9,3,2,4,8], the 3rd largest element is4.
[9,3,2,4,8]
4
In array[1,2,3,4,5], the 1st largest element is5, 2nd largest element is4, 3rd largest element is3and etc.
[1,2,3,4,5]
5
3
Challengearrow-up-right
O(n) time, O(1) extra memory.
Tagsarrow-up-right
Sortarrow-up-right Quick Sortarrow-up-right
https://aaronice.gitbooks.io/lintcode/content/data_structure/kth_largest_element.htmlarrow-up-right
Last updated 5 years ago