Medium · Math
K Closest Points to Origin
Given an array of points [x, y] and an integer k (1 ≤ k ≤ n), return the k points closest to the origin (0, 0) by Euclidean distance, in any order; the input guarantees that this set is unique.
Examples
Example 1
[[1,3],[-2,2]], k=1Output: (-2,2)
Example 2
[[3,3],[5,-1],[-2,4]], k=2Output: (3,3), (-2,4)
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.