From LeetCode. Euclidean distance sorting. Solve the geometry problem "K Closest Points to Origin".
Examples
Input:[[[1,3],[-2,2]],1]
Output:[[-2,2]]
Input:[[[3,3],[5,-1],[-2,4]],2]
Output:[[3,3],[-2,4]]
Hints
Distance from origin is sqrt(x² + y²). You never need the actual square root — compare squared distances to sort, which is faster and avoids floating-point issues.
Build a max-heap of size k: push each point's squared distance, and pop the largest when the heap exceeds k. The k points remaining in the heap are your answer.
When multiple points tie on distance, any ordering is accepted. If k equals the total number of points, return all points unchanged.