K Closest Points to the Origin

medium
Unit 20 · Data Structures0/3 to milestone

Return the k points closest to (0, 0) by Euclidean distance, sorted by distance (ties by x, then y). Use a max-heap of size k (via heapq with negated keys) so it runs in O(n log k).

#heap#geometry2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
K Closest Points to the Origin · TechGradify