K Closest Points to Origin | LeetCode 973 | C++, Java, Python

preview_player
Показать описание

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

May LeetCoding Challenge | Problem 30 | K Closest Points to Origin | 30 May,
Facebook Coding Interview question,
google coding interview question,
leetcode,
K Closest Points to Origin,
K Closest Points to Origin c++,
K Closest Points to Origin Java,
K Closest Points to Origin python,
K Closest Points to Origin solution,
973. K Closest Points to Origin,
Max Heap,
priority queue,

#Facebook #CodingInterview #LeetCode #MayLeetCodingChallenge #Google #Amazon #MaxHeap
Рекомендации по теме
Комментарии
Автор

I was just struggling with this problem and you have made it look like a piece of cake. Thank you very much! :)

chetnavarma
Автор

The for loop can be simplified as follows:

for(int[] temp: points){
pq.add(new Point(temp));
if(pq.size() > K){
pq.remove();
}
}

meharkaur
Автор

Can't we just take priority queue with min heap and just the pop the element k times

Star_Bawa
Автор

Sir, why do we need to define the comparison method in a structure?

medhak
visit shbcf.ru