83. Closest Points
Medium
Given a list of points [x, y] and an integer k, return the k points closest to the origin. Sort the result by increasing distance and, in case of ties, by increasing x and then increasing y.
Example 1
Input: pontos = [[2, 1], [-1, 1], [4, 0]], k = 2
Output: [[-1, 1], [2, 1]]
Example 2
Input: pontos = [[3, 4], [0, 2]], k = 1
Output: [[0, 2]]
Constraints
- 1 <= k <= pontos.length <= 10^4
- -10^4 <= x, y <= 10^4
HeapSorting
Saved in this browser
Caso 1
pontos =
[[2,1],[-1,1],[4,0]]
k =
2
Expected =
[[-1,1],[2,1]]
Caso 2
pontos =
[[3,4],[0,2]]
k =
1
Expected =
[[0,2]]
Run checks these 2 cases. Submit runs all 6, including hidden ones.