← Trees, Graphs & DP
#10 most askedVery commonMediumHeap

Kth Largest Element in an Array

New to Heap? Learn it from scratch first
Heaps & Priority Queues β†’
🏒 Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

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.

Python
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.