This topic is a practice problem inside the Heap / Priority Queue module. The goal is not to memorize the title: reconstruct the problem it solves, the mechanism that makes it work, and the signal that tells you when to use it.
Remember the shape, not the sentence
“K-th anything, streaming medians, always-cheapest-first — reach for a heap.”
What problem does this solve?
Start from the engineering problem rather than the definition. K Closest Points to Origin exists because a system needs a reliable way to handle a recurring constraint inside Heap / Priority Queue. Ask what would become slow, ambiguous, unsafe, or impossible without it.
How the mechanism works
Break the idea into observable steps. The useful mental model is: input → transformation → decision or state change → output. Keep each step small enough that you can redraw it from memory. The surrounding module is the context: K-th anything, streaming medians, always-cheapest-first — reach for a heap.
When to reach for it
Use nearby concepts as contrasts. In this module, compare K Closest Points to Origin with Heaps: min/max, push/pop in O(log n), heapify in O(n), Kth Largest Element in a Stream, Last Stone Weight. The distinction matters because good engineering choices depend on the constraints, not on memorizing isolated definitions.
See the mechanism before you memorize it
One diagram, one causal story, one reconstruction task.
K Closest Points to Origin — causal map
Frame
State the problem and the constraints before naming the technique.
Transform
Apply the core mechanism of K Closest Points to Origin and track what state changes.
Observe
Inspect the artifact, output, invariant, or behavior produced by the mechanism.
Transfer
Explain where the same idea appears elsewhere in DSA Patterns.
Draw the idea yourself
Rebuild the core flow on a real canvas before moving to the worked walkthrough.
Walk the system
Frame
State the problem and the constraints before naming the technique.
Transform
Apply the core mechanism of K Closest Points to Origin and track what state changes.
Observe
Inspect the artifact, output, invariant, or behavior produced by the mechanism.
Transfer
Explain where the same idea appears elsewhere in DSA Patterns.
Reconstruction card
Use the card as a generative note, not a summary to copy. Fill it from memory after the explanation.
TOPIC: K Closest Points to Origin
MODULE: Heap / Priority Queue
TYPE: practice problem
PROMPT
What problem does it solve?
What changes step by step?
What evidence proves it worked?
When would you choose something else?What usually goes wrong
Close the tab. Rebuild it from memory.
Read the question, answer aloud, then reveal.
What problem is K Closest Points to Origin designed to solve?Reveal answer
It addresses a recurring constraint inside Heap / Priority Queue. A strong answer names the input, the core mechanism, and the result rather than repeating the title.
What are the four stages of the mental model?Reveal answer
Frame the problem → transform the input/state → observe the evidence → transfer the idea to a new scenario.
Median from a stream: the two-heap invariant?Reveal answer
Max-heap holds the smaller half, min-heap the larger half; sizes differ by at most 1. Median is a top or the average of tops.
Kth largest in array: why keep a min-heap of size K?Reveal answer
The heap keeps the K largest seen so far; its root is the smallest of those — the Kth largest overall.
Make this idea travel.
Connect it next to: Why pattern-based learning beats grinding • Set up your mistakes log + template notebook • Your spaced revision calendar (Day 1 / 3 / 7 / 21) • Big-O intuition builder: visualize growth rates.