Skip to content

Resource · Guide or article

Heap cheatsheet for coding interviews

Covers heaps and priority queues, which the page treats as the same thing for interviews, with a focus on spotting top-k problems and repeated removal of the smallest or largest item.

Reviewed

Open the original: Heap cheatsheet for coding interviews (opens the original site in a new tab)

Practice this topicOpens the practice interviewer in Technical / coding mode; choose a question there.

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

A heap is a specialized tree-based data structure which is a complete tree that satisfies the heap property.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Cheatsheet

What it covers

  • Max heap and min heap properties defined over every subtree.
  • Library table: C++ priority_queue, Java PriorityQueue, Python heapq, and no built-in for JavaScript.
  • Costs: O(1) to read the min or max, O(log n) insert and remove, O(n) heapify.
  • Top-k pattern: keep a min heap of size k and pop once it grows past k, with a tip to negate values in Python heapq.

How to use it

PrepKit study advice, not a claim made by the source.

Solve one top-k problem twice, once by sorting and once with a size-k heap, and state the time complexity of each. Explain why popping the minimum leaves you with the k largest values.

Scope and limitations

Short page with one technique and no corner cases. It does not show how to build a heap yourself, which matters if you interview in JavaScript. Ends with an imported Recommended courses block whose links are not in the recorded file, so PrepKit has not reviewed them.

Access and format

Web page on techinterviewhandbook.org, free to read online in English; the text comes from the MIT-licensed yangshun/tech-interview-handbook repository.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: e1d28e8886c0

Evidence behind this overview
  • apps/website/contents/algorithms/heap.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email