PythiloMedium · 25 min · Task 55 of 100 · progress kept in this browser

Kth largest with a heap

Return the kth largest integer, counting duplicates. k is between 1 and the input length. Use O(k) auxiliary space.

import heapq
heap = [3, 5]
heapq.heappush(heap, 4)
heapq.heappop(heap)
print(heap[0])
Your task

Return the kth largest integer, counting duplicates. k is between 1 and the input length. Use O(k) auxiliary space.