Coding

Find the K closest points to the origin.

Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

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

Output: [[3,3], [-2,4]]

Explanation: The squared distances are 18, 26, and 20 respectively. The two smallest distances belong to [3,3] and [-2,4].

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions