Kth Largest Element
mediumFind the kth largest element using QuickSelect (partition)
Kth Largest (QuickSelect)
Key Insight
Partition once, then only recurse into the side containing the target index
Step 1Setup
k=2, target index = 6-2 = 4
3
02
11
25
36
44
5Find 2nd largest in [3, 2, 1, 5, 6, 4]. That's index 4 in sorted order.
1 / 4
Learn the Pattern
SortingUse sorting as a preprocessing step to simplify problems, or apply partition logic for in-place rearrangement. Many interview problems become trivial once the array is sorted.
HeapUse a heap (priority queue) when you repeatedly need the minimum or maximum of a changing set while also inserting and deleting values efficiently.