Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
The distance between two points on the X-Y plane is the Euclidean distance: sqrt(x^2 + y^2).
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).
points = [[1,3],[-2,2]], k = 1[[-2,2]]points = [[3,3],[5,-1],[-2,4]], k = 2[[3,3],[-2,4]]1 <= k <= points.length <= 10^4-10^4 <= xi, yi <= 10^4Expected time complexity: O(n log k)Run your code to see results
Use Cmd+Enter to run