From LeetCode. Euclidean distance sorting. Solve the geometry problem "K Closest Points to Origin".
Examples
Input:[1,2,3]
Output:0
Input:[2,3,4]
Output:0
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.
K Closest Points to Origin
**From LeetCode.** Euclidean distance sorting. Solve the geometry problem "K Closest Points to Origin".