LeetCode75-215-Kth-Largest
🧠 Summary of Thoughts
Key Observations
- You don’t need to fully sort the array
- The problem is essentially:
- Find the element at index n - k (0-based sorted order)
Common Approaches
Sorting:
- Sort the array
- Return nums[n - k]
- Time: O(n log n)
Min Heap:
- Maintain a min heap of size k (PriorityQueue is a min heap by default)
- Keep only the k largest elements
- The top of heap = answer
Why it works:
- Always remove the smallest → keep largest k elements
- Time: O(n log k)
- Space: O(k)
Quickselect:
- Partition-based (like quicksort)
- Average: O(n)
- Worst: O(n²)
✅ Code(Java)
- Sorting
1 | |
- Min Heap
1 | |
LeetCode75-215-Kth-Largest
https://powersixxx.github.io/leetcode-blog/2026/04/11/LeetCode75-215-Kth-Largest/