Heap / Priority Queue
Keep a heap so the smallest or largest item is always ready to take in logarithmic time. The tell is 'the k largest', 'the k most frequent', or repeatedly taking the best next item, as in Kth Largest Element in an Array. It avoids sorting everything.
15 problems · 4 with a video · 3 to practice in an AI round
| # | Problem | Difficulty | Video | AI round |
|---|---|---|---|---|
| 1 | Top K Frequent Elements | Medium | AI round | |
| 2 | Kth Largest Element in an Array | Medium | — | AI round |
| 3 | Task Scheduler | Medium | — | |
| 4 | Sort Characters By Frequency | Medium | — | |
| 5 | Reorganize String | Medium | AI round | |
| 6 | K Closest Points to Origin | Medium | — | |
| 7 | Sort an Array | Medium | — | |
| 8 | Find K Pairs with Smallest Sums | Medium | — | |
| 9 | Last Stone Weight | Easy | ||
| 10 | Furthest Building You Can Reach | Medium | — | |
| 11 | Car Pooling | Medium | — | |
| 12 | Maximum Number of Events That Can Be Attended | Medium | — | |
| 13 | Single-Threaded CPU | Medium | — | |
| 14 | Rearrange String k Distance Apart | Hard | — | |
| 15 | Maximum Product After K Increments | Medium |
Sort by what interviews ask
Sign in to see how many companies ask each problem, sort all 500 by it or by likes, and tick off what you solve.
Practice in an AI round
Three of these are AI rounds: 30 minutes, an AI agent beside your code, then a scored report.
Practice Top K Frequent Elements in an AI roundYour first AI round is free.