Heaps and priority queues interview questions

Min-heaps by hand and with heapq: the k largest, merging sorted feeds, running medians and greedy choices that always take the smallest or biggest next.

5 quick facts

– interview-ready · 10 questions in this topic

– of 10 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. Push values into a min-heap by handPredict
  2. The k-th biggest readingFill the blank
  3. Merge many sorted feeds into onePredict
  4. The k depots nearest the warehousePredict
  5. Fewest time slots when each job type needs a cooldownPredict
  6. Median after each new readingPredict
  7. Smash the two heaviest rocks until one is leftPredict
  8. Cheapest way to join ropes into onePredict
  9. How a binary heap worksPredict
  10. Heap, sort or quickselect?Pick the fix

Practise this topic

Flashcards · 20

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 10 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 2 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license