K Closest Points to Origin

Try to solve the K Closest Points to Origin problem.

Statement

Given an array of points on a plane, where the plane is a 2-D array with (x, y) coordinates, find the kk closest points to the origin (0,0)(0, 0).

Note: Here, the distance between two points on a plane is the Euclidean distance: x2+y2 \sqrt{x^2 + y^2}

Constraints:

  • 1≤1 \leq k ≤\leq points.length ≤103\leq 10^3
  • −104<-10^4 < x[i], y[i]<104< 10^4

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy