01 · Question
Given an array of points where points[i] = [xi, yi] and an integer k, return the k closest points to the origin (0, 0).
02 · Analysis
Squared distance preserves distance order without a square root. The displayed implementation pushes all n points into a min-heap, then pops k: O(n log(n+1) + k log(n+1)) time and O(n) auxiliary space, plus output. Require 0 <= k <= n. Heapifying the initial entries would make construction O(n); a size-k max-heap is the O(k)-space alternative. Use a wide type before squaring large coordinates.