← All problems
K Closest Points to Origin
Given an array of points in the plane, return the k points closest to the origin (0, 0). Avoid computing all distances and fully sorting when k is much smaller than n.
Complexity
Time O(n log k), Space O(k)
Common pitfalls
- Computing sqrt unnecessarily
- Min-heap of all points
Your solution
Log in to save your code and track progress.