Given an array of points on a 2D plane, return the k closest points to the origin (0, 0).
Distance is Euclidean: for point (x, y), distance is sqrt(x² + y²). You can compare squared distances to avoid the square root.
With points = [[1,3], [-2,2]] and k = 1:
- Distance of
[1,3]:sqrt(1 + 9) = sqrt(10). - Distance of
[-2,2]:sqrt(4 + 4) = sqrt(8). [-2,2]is closer. Return[[-2,2]].
The answer can be in any order.
Constraints: .