As reported: LinkedIn Senior Software Engineer, Systems Infrastructure (Sep 2025), DSA round 1: the K points nearest to the origin in 2D, extended to the points nearest to any given point in 2D. A question similar to LRU Cache followed.
Given an array of points where points[i] = [xi, yi] and an integer k, return the k points closest to the origin (0, 0) by Euclidean distance. The answer may be in any order; it is guaranteed to be unique.
This is LeetCode 973 — K Closest Points to Origin.
Example 1
points = [[1,3],[-2,2]], k = 1
Output: [[-2,2]]
Example 2
points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3],[-2,4]]
Constraints: 1 ≤ k ≤ points.length ≤ 10^4; −10^4 ≤ xi, yi ≤ 10^4.
Code runner format: LeetCode's test-case format, one JSON value per line (one line per argument). Implement kClosest(points, k) (any order is accepted); the harness prints the result as JSON.
Follow-ups
- Return the
kpoints nearest to any given point in 2D, not only the origin.