Its worth to note that priority queue in java does not strictly sort the values. It only sorts in a way that first element is the least and still have the rest of the elements unsorted. Also, practically speaking, slightly faster way would be to keep a min heap and add all points into it, then populate result with first k elements of min heap.
Its worth to note that priority queue in java does not strictly sort the values. It only sorts in a way that first element is the least and still have the rest of the elements unsorted.
Also, practically speaking, slightly faster way would be to keep a min heap and add all points into it, then populate result with first k elements of min heap.
Please share the link to problem in the description. It helps.
Nyc tutotial on problem solving
does it matter the order of the array parameters in the overloaded compare method?