LC 973
LeetCode 973 · Medium

K Closest Points to Origin

Return the k points closest to the origin.

Heap → · High frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the heap shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Heap — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

Compare by squared distance (no sqrt needed). A size-k max-heap keeps the k closest in O(n log k); quickselect on distance gives expected O(n).

AspectValue
PatternHeap
Recognise it byK nearest by distance.
Time complexityO(n log k)
Space complexityO(k)
DifficultyMedium

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.