K Nearest Drop Points
mediumA delivery drone is docked at the depot — the origin (0, 0) of the city grid. Dispatch hands you a list of pending drop points, each [x, y], and the drone's battery only covers the k closest drops this run.
Return those k points (any order), measuring straight-line (Euclidean) distance to the origin. The answer is guaranteed unique — no distance ties straddle the cutoff.
Example 1
in points = [[1, 3], [-2, 2]], k = 1
out [[-2, 2]]
Squared distances: 10 vs 8 — [-2, 2] is closer.
Example 2
in points = [[3, 3], [5, -1], [-2, 4]], k = 2
out [[3, 3], [-2, 4]]
Squared distances 18, 26, 20 — keep the two smallest.
Constraints
- · 1 <= k <= len(points) <= 2000
- · -10^4 <= x, y <= 10^4
- · the set of k closest points is unique
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.