DIY: K Closest Points to Origin

Solve the interview question "K Closest Points to Origin" in this lesson.

Problem statement

We have a list of points on the plane. Find the K closest points to the origin (0, 0).

Note: Here, the distance between two points on a plane is the Euclidean distance.


The input will be a list of points and a value k. The following is an example input:

points = [[1,3],[-2,2]] 
k = 1


The output will be the k points from the points list that are closest to the origin. For the above input, the output will be:


Level up your interview prep. Join Educative to access 70+ hands-on prep courses.