Loading problem…
Pick the best time and extra space complexity.
function topK(nums, k) { const heap = new MinHeap() for (const num of nums) { heap.push(num) if (heap.size() > k) heap.pop() } return heap.toArray() }