K Closest Points to Origin
Problem
You are given a list of points on the plane, points[i] = [x, y], and an integer k. Return the k points that are nearest to the origin (0, 0) under Euclidean distance. The result may be in any order, and the answer is guaranteed to be unique (there are no ties at the k-th boundary that would make the set ambiguous).
- Up to around ten thousand points, and
kis always a valid count for the given list. - Coordinates fit comfortably in a normal int, positive or negative.
Examples
points = [[2,4],[-3,1]], k = 1→[[-3,1]]. Squared distances are 20 and 10, so(-3, 1)is closer.points = [[4,2],[6,-3],[-1,5]], k = 2→[[4,2],[-1,5]]in any order. Squared distances 20, 45, 26; the two smallest are 20 and 26.points = [[0,0]], k = 1→[[0,0]]. The origin itself at distance 0.
Hints
- You never need the actual distance, only a way to compare two points. What can you drop from the formula?
- Sorting all points is O(n log n). If
kis small, can you avoid ordering points that will never be in the answer? - Max-heap of size
kkeyed on squared distance (O(n log k)), or quickselect on squared distance (O(n) average).
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.