#10 most askedVery commonMediumHeap
Kth Largest Element in an Array
New to Heap? Learn it from scratch firstHeaps & Priority Queues β
π’ Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Return the kth largest number (not the kth distinct). Try to beat sorting.
find_kth_largest([3, 2, 1, 5, 6, 4], 2) β 5
π§ͺ Practice
Write your solution, then press Run tests. Explain your approach out loud as you go.
import heapq
def find_kth_largest(nums, k):
pass
Output appears here. Press Run or Ctrl/β + Enter.
Try it first. Struggling for a few minutes is how it sticks.