5.Kth Largest Element
Last updated
Was this helpful?
Last updated
Was this helpful?
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
.
In array[1,2,3,4,5]
, the 1st largest element is5
, 2nd largest element is4
, 3rd largest element is3
and etc.
O(n) time, O(1) extra memory.