973. K Closest Points to Origin

Practice K Closest Points to Origin for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Each points[i] is [x, y] on a plane. Return the k points closest to the origin (0, 0) by straight-line distance, in any order. The tests are built so the set of k closest points is unique.

Example

points = [[1,3],[-2,2]], k = 1          ->  [[-2,2]]
points = [[3,3],[5,-1],[-2,4]], k = 2   ->  [[3,3],[-2,4]]

Constraints