LeetCode 215 ·
Medium
Kth Largest Element in an Array
Find the kth largest element in an unsorted array.
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.
| Aspect | Value |
|---|---|
| Pattern | Heap |
| Recognise it by | Kth largest without full sort. |
| Time complexity | O(n) avg |
| Space complexity | O(1) |
| Difficulty | Medium |
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.