Use a min-heap of size k.
Iterate through the array. Maintain a heap containing the k largest elements seen so far:
- If heap size <
k, add the element. - If element > heap minimum, replace the minimum with this element.
After processing all elements, the heap minimum is the kth largest.
Alternatively, use Quickselect (partitioning like Quicksort) for average time, but the heap approach is simpler and more predictable.