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 is the Euclidean distance. You may return the answer in any order.
30:00
Java
K Closest Points to Origin
medium
Topics
Companies
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 is the Euclidean distance. You may return the answer in any order.
Example 1:
Input: {"points":[[1,3],[-2,2]],"k":1}
Output: [[-2,2]]
Constraints:
1≤k≤points.length≤104
−104≤xi,yi≤104
Input
arr ={"points":[[1,3],[-2,2]],"k":1}
Find 1 closest points to origin from 2 points
Points (k=1)
O(1,3)(-2,2)
Current
In Heap
Result
Max Heap (by distance)
Empty
Variables
No variables to display
DepthFunction Call
Stack empty
0/6
Asked in these interview guides
Company guides that list this problem among their sample questions.