Hi,
I want some comments on whether my method here is correct or not for this question. Shouldn’t we just calculate distance in the beginning for each star before inserting. We will fill the maxHeap to its initial capacity k in the beginning . Once its filled we only need to do the inserts and removal for stars with distance < maxHeap.peek(). This will reduce the number of operations on heap in case if first k stars in the file are closest to earth and k<<n.