Marks :10
: 3 | : 3
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).
The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). If two points have the same distance, then return the one with a smaller x coordinate.
Sort the k coordinates in ascending order of x coordinate and then over y coordinate and print the output.
Constraints : 1 <= n <= 10^4 -10^4 < xi, yi < 10^4
The first line contains an integer n and k, which denotes the number of points and the value k. the next n lines contain 2 space serrated integers each, denoting the X and the Y coordinate
Output k lines each containing 2 space separated integers denoting the k closest points.
3 2 1 2 3 4 1 -1
1 -1 1 2
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.