import heapq
def findKLargest(lst, K):
if not lst or len(lst) < K:
return -1
pq = lst[0 : K]
heapq.heapify(pq)
for i in range(K, len(lst)):
if lst[i] > pq[0]:
heapq.heapreplace(pq, lst[i])
return pq[0]
lst = [100, 88, 98, 80, 50, 12, 35, 70, 60, 97, 85, 89]
K = 4
print(findKLargest(lst, K))
'''
run:
89
'''