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

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • LeetCode Solutions: • LeetCode Solutions | L...
    June LeetCoding Challenge: • Playlist
    May LeetCoding Challenge: • Playlist
    *** Best Books For Data Structures & Algorithms for Interviews:*********
    1. Cracking the Coding Interview: amzn.to/2WeO3eO
    2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
    3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
    4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
    5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
    6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
    *****************************************************************************
    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

КОМЕНТАРІ • 8

  • @chetnavarma3486
    @chetnavarma3486 2 роки тому +2

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

  • @meharkaur7326
    @meharkaur7326 4 роки тому +1

    The for loop can be simplified as follows:
    for(int[] temp: points){
    pq.add(new Point(temp));
    if(pq.size() > K){
    pq.remove();
    }
    }

  • @vireshdeshamane
    @vireshdeshamane Рік тому +1

    legendary

  • @medhak7322
    @medhak7322 4 роки тому

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

  • @Star_Bawa9
    @Star_Bawa9 2 роки тому

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