K Closest Points to Origin
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

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:
  • 1kpoints.length1041 \leq k \leq \text{points.length} \leq 10^4

  • 104xi,yi104-10^4 \leq x_i, y_i \leq 10^4

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