Keep a min-heap of size k with the k largest values.
Push each number; if heap grows beyond k, pop the smallest. The heap’s root ends as the k-th largest.
After processing all values, exactly the k largest remain in the heap; the smallest of them is the k-th largest.
Keep a min-heap of size k with the k largest values.
Push each number; if heap grows beyond k, pop the smallest. The heap’s root ends as the k-th largest.
After processing all values, exactly the k largest remain in the heap; the smallest of them is the k-th largest.