points lists spots on a flat map, each written as [x, y]. Return the k points that are nearest to the centre (0, 0), measured by straight-line distance, √(x² + y²).
The inputs are chosen so the k nearest points are never in doubt: the k-th nearest point is strictly closer than every point left out. Ties inside the answer are fine. You may return the k points in any order.
The same spot may be listed more than once; each copy is a separate point.
The squared distances are 9 + 1 = 10, 0 + 4 = 4 and 4 + 4 = 8. The two smallest belong to [0,2] and [-2,-2]. [[-2,-2],[0,2]] is just as correct.
[1,1] is nearest (squared distance 2). [5,5] and [-1,7] are tied at 50, and both make the cut, since the only point left out, [6,-4], is farther at 52.
Both copies of [2,2] (squared distance 8) beat [-3,0] (9).
Constraints
1 <= k <= points.length <= 10⁴points[i].length == 2-10⁴ <= x, y <= 10⁴k < points.length, the k-th smallest distance is strictly less than the (k+1)-th.Comparing x² + y² orders points exactly as the true distance does, so you never need a square root. The task is then picking the k smallest of n numbers.