Given an array of 2D points points and an integer k, return the k points closest to the origin (0, 0). The distance between two points is the Euclidean distance. You may return the answer in any order.
Constraints: 1 ≤ k ≤ points.length ≤ 10⁴ · −10⁴ ≤ xᵢ, yᵢ ≤ 10⁴ · the answer is guaranteed to be unique (up to order).
Twelve points scattered around the origin. Your job: find the 3 closest. Go. (You have about two seconds before your eyes start jumping between coordinates, comparing distances you can't compute in your head.)
The obvious move is the one you always reach for first: compute every distance, sort the list, take the first 3. It works. But pay attention to what happens to points 4 through 12 — the nine points you'll throw away the instant sorting finishes.
k = 3