K Closest Points to Origin

Medium · Heap & Priority Queue · about 15 minutes

Asked at Meta, Amazon, Uber, DoorDash, Toast, Grab, Swiggy.

Each entry of points is a coordinate pair [x, y]. Pick the k points nearest to (0, 0) by straight-line distance and return them in any order; the tests ensure there's no tie at the boundary.

Related guides