K Closest Points to Origin
Medium

Problem Statement

Given a list of points on a 2D plane, find the K closest points to the origin (0, 0). There can be multiple Solutions, Give any solution out of multiple solutions

Examples

1Example 1
Input:
{ "points": [ [ 1, 3 ], [ -2, 2 ] ], "k": 1 }
Output:
[ [ -2, 2 ] ]
2Example 2
Input:
{ "points": [ [ 3, 3 ], [ 5, -1 ], [ -2, 4 ] ], "k": 2 }
Output:
[ [ 3, 3 ], [ -2, 4 ] ]
3Example 3
Input:
{ "points": [ [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] ], "k": 1 }
Output:
[ [ 1, 1 ] ]
Loading...

Sign in to Run Code and Submit