Return the k points of points that are closest to the origin (0, 0), using the straight-line distance. Sort them by squared distance x² + y², nearest first; points at the same distance go by x and then by y (increasing). Points can repeat.
For points = [[1, 3], [-2, 2]] and k = 1 the answer is [[-2, 2]].
Example 1
Input:
k_closest([[1, 3], [-2, 2]], 1)
Output:
[[-2, 2]]
Example 2
Input:
k_closest([[3, 3], [5, -1], [-2, 4]], 2)
Output:
[[3, 3], [-2, 4]]
0 <= k <= len(points) <= 100000-10**4 <= x, y <= 10**4No results yet
Run your code to check it against the examples, or submit to run every test.