The Kth Largest Element in an Array interview question is one of the most popular algorithmic challenges. You are given an unsorted array and need to find the largest element. Note that it is the largest in sorted order, not the distinct element.
This question is a favorite at Google, Amazon, and Uber because it allows for multiple solutions with different trade-offs. It evaluations your knowledge of Sorting, Heaps, and most importantly, the Quickselect algorithm. it tests if you can optimize from to average time.
There are three main patterns:
arr[n - k].[3, 2, 3, 1, 2, 4, 5, 5, 6], k = 4
[1, 2, 2, 3, 3, 4, 5, 5, 6]Master Quickselect. It is the most "senior" answer to this problem. Be prepared to explain why it is on average (using the Master Theorem or a geometric series argument). This is a core Quickselect interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Kth Largest Integer in the Array | Medium | Solve | |
| K Closest Points to Origin | Medium | Solve | |
| Query Kth Smallest Trimmed Number | Medium | Solve | |
| Wiggle Sort II | Medium | Solve | |
| Top K Frequent Elements | Medium | Solve |