LC 215
LeetCode 215 · Medium

Kth Largest Element in an Array

Find the kth largest element in an unsorted array.

Heap → · Very high frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the heap shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Heap — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

A size-k min-heap gives O(n log k). Quickselect (partition around a pivot, recurse into the side holding rank k) gives expected O(n) and is the answer interviewers fish for.

AspectValue
PatternHeap
Recognise it byKth largest without full sort.
Time complexityO(n) avg
Space complexityO(1)
DifficultyMedium

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.