Skip to content

Heap (Priority Queue) problems,
and the tell.

You repeatedly need the smallest or largest thing, and the data keeps changing. 115 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. You repeatedly need the smallest or largest thing, and the data keeps changing.

The mechanism. A heap keeps the extreme at the top for log n per insert or removal. For top k, keep a heap of size k and the cost drops to n log k.

What goes wrong. Rebuilding or re-sorting after every change. The point of the heap is that you never have to.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Maximum Performance of a TeamHardasked at 5 companies
  2. Strong Password CheckerHardasked at 3 companies
  3. Construct String With Repeat LimitMediumasked at 2 companies
  4. Mark Elements on Array by Performing QueriesMediumasked at 2 companies
  5. Minimum Cost to Buy ApplesMediumasked at 2 companies
  6. Sell Diminishing-Valued Colored BallsMediumasked at 2 companies
  7. Sort an ArrayMediumasked at 2 companies
  8. Find the Safest Path in a GridMediumasked at 2 companies
  9. Jump Game VIMediumasked at 1 companies
  10. Design a 3D Binary Matrix with Efficient Layer TrackingMediumasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About heap (priority queue) problems.

Free to start, no card.

Start practising
How do I know a problem is a heap (priority queue) problem?

You repeatedly need the smallest or largest thing, and the data keeps changing.

How many heap (priority queue) problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 115, split roughly 7 easy, 66 medium and 42 hard in the sample we show, so work up rather than across.

What goes wrong most often in heap (priority queue) problems?

Rebuilding or re-sorting after every change. The point of the heap is that you never have to.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.