43. K Closest Points to Origin

Return the k points closest to the origin (0, 0) by Euclidean distance, in any order. The answer is unique.

Example 1

Input: points = [[1,3],[-2,2]], k = 1
Output: [[-2,2]]

Example 2

Input: points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3],[-2,4]]
Hint 1

Compare squared distances: no square roots needed.

Hint 2

Keep a max-heap of size k and evict the farthest point.

HeapGeometry