Meeting Rooms III - Leetcode 2402 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ค. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
    🐦 Twitter: / neetcode1
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    Problem Link: leetcode.com/problems/meeting...
    0:00 - Read the problem
    0:30 - Drawing Explanation
    8:48 - Coding Explanation
    leetcode 2402
    #neetcode #leetcode #python

ความคิดเห็น • 43

  • @NeetCodeIO
    @NeetCodeIO  5 หลายเดือนก่อน +44

    Sorry I'm a little late today, but better late than never! 🚀🚀

    • @satyamjha68
      @satyamjha68 5 หลายเดือนก่อน +1

      No problem! Love your leetcode content as always!

    • @AmrElmohtaseb
      @AmrElmohtaseb 5 หลายเดือนก่อน

      Thank you!! This is the video I wait for every day.

    • @aseshshrestha8012
      @aseshshrestha8012 5 หลายเดือนก่อน

      Why did you stop posting in your another channel? Why another channel?

  • @SairamDasari2000
    @SairamDasari2000 5 หลายเดือนก่อน +14

    I thought my streak is going to end , thanks mate ❤❤

  • @SanketBhat7
    @SanketBhat7 5 หลายเดือนก่อน +7

    I solved it without help!!! But at what cost😅? I took 3 hours, used a "TreeMap"🙃🙃 and my solution beats only 5% of others. But I am still happy that I am able to solve, something is better than nothing. Came here to learn how to do it the right way.

    • @yang5843
      @yang5843 5 หลายเดือนก่อน +1

      fwiw my java solution beats 23%, I posted the code as a comment to this video

  • @user-jf7xb1lb2z
    @user-jf7xb1lb2z 5 หลายเดือนก่อน +3

    Bro you are a lifesaver, there was absolutely no way I could have solved this on my own.

  • @NH-hq7ly
    @NH-hq7ly 5 หลายเดือนก่อน +16

    Thanks for the video. My level is too low to solve this hard question. I'm just here to learn

  • @aniketpatel8655
    @aniketpatel8655 5 หลายเดือนก่อน

    You explained things so easily! Thank you, dude.

  • @hoyinli7462
    @hoyinli7462 5 หลายเดือนก่อน +2

    I love your lc video. I can see you've uploaded a solution, which means I can learn from you when I can't solve it. At the same time I don't see any spoiler, so I can try first.
    Great video as always!

  • @nicolasguillenc
    @nicolasguillenc 5 หลายเดือนก่อน

    This one was rough, thanks man!

  • @razataggarwal7365
    @razataggarwal7365 5 หลายเดือนก่อน

    Same thought process ! 👌

  • @shashwatkumar3079
    @shashwatkumar3079 5 หลายเดือนก่อน

    I figured out what I needed to do but cant't figure out the approach of using two heaps. Good question.

  • @sherloccode6272
    @sherloccode6272 5 หลายเดือนก่อน

    Love this explanation

  • @trueArcticFox
    @trueArcticFox 5 หลายเดือนก่อน

    Thanks!

  • @chaitanyasharma6270
    @chaitanyasharma6270 5 หลายเดือนก่อน +1

    explain meeting rooms 2 with priority queue as well

  • @iamabominable7462
    @iamabominable7462 5 หลายเดือนก่อน +4

    Never been here this early lol
    Love your content 😄

    • @NeetCodeIO
      @NeetCodeIO  5 หลายเดือนก่อน

      ty :)

  • @hangchen
    @hangchen 4 หลายเดือนก่อน

    7 days ago, just about time for me!

  • @gokukakarot6323
    @gokukakarot6323 8 วันที่ผ่านมา

    In the heap, is it possible to store the difference between two meetings (end,start, meeting_idx) ? Re: Naaah ignore

  • @tarunmali6228
    @tarunmali6228 3 หลายเดือนก่อน

    Hi, when this problem will be added to the neecode website list?

  • @sophiophile
    @sophiophile 5 หลายเดือนก่อน +1

    Can you use heapq methods like heappop on a list that you never heapified like that? 3:16 If so that's awesome. Does that mean if your list is already a (eg min) heap, those operations just work?

    • @NeetCodeIO
      @NeetCodeIO  5 หลายเดือนก่อน +1

      Yeah exactly, heaps are stored as lists in python. Even in languages like Java they are implemented with arrays / ArrayList under the hood

    • @sophiophile
      @sophiophile 5 หลายเดือนก่อน

      @@NeetCodeIO That's awesome. That's the thing I love about Python. You always discover new ways that something can be done a little lazier, haha.
      I always assumed that while they could be accessed like lists, it was either:
      * some magic under the hood so you could use the same methods as on a normal list object
      * a list with the same data was generated when you needed to interact with that object type, while there is some tree that is the actual heap somewhere else in memory

  • @suvajitchakrabarty
    @suvajitchakrabarty 4 หลายเดือนก่อน

    When rooms are not available, and we look at the used heap, why do we only pop the first value from used. What if there were other values with the same end time, would we not want to pop all the nodes with the same end time, and use the one with the minimum room number?

    • @suvajitchakrabarty
      @suvajitchakrabarty 4 หลายเดือนก่อน

      Ah okay never mind, I guess I realized later that the min heap comparator function will take care of that automatically. Sorry, was using Javascript, and was using a class for the min heap that I wrote myself.

  • @WatchTower71
    @WatchTower71 5 หลายเดือนก่อน

    How long did it take for you to come up with a solution for this? I came up with a solution but because of the constraints it failed 10 TCs.

  • @vivekragireddy6941
    @vivekragireddy6941 5 หลายเดือนก่อน

    can anyone post the c++ version of code for this?

  • @Moch117
    @Moch117 5 หลายเดือนก่อน +1

    You solved without hints ?

  • @synthesiakin2543
    @synthesiakin2543 5 หลายเดือนก่อน +1

    What do you use to draw on the screen?

    • @NeetCodeIO
      @NeetCodeIO  5 หลายเดือนก่อน +3

      paint 3d and a mouse

    • @yaswanthkosuru
      @yaswanthkosuru 5 หลายเดือนก่อน +1

      ​@@NeetCodeIOare u joking 😅

    • @navaneethku
      @navaneethku 5 หลายเดือนก่อน

      I don't think he is joking@@yaswanthkosuru

  • @electricindro2236
    @electricindro2236 5 หลายเดือนก่อน

    Brilliant!

  • @JourdanOoi-wp2lh
    @JourdanOoi-wp2lh หลายเดือนก่อน

    this solution no longer working for anyone else?

  • @alieeldeenahmed2278
    @alieeldeenahmed2278 5 หลายเดือนก่อน

    I reach test cases 69/82
    I give up 😅😅

  • @bouzie8000
    @bouzie8000 5 หลายเดือนก่อน

    I actually don't think this is a leetcode hard, more like a medium. I think there are enough cues in the question that let you know exactly what data structure to use to solve this. It also helps if you've solved meeting rooms II before. But I see a lot of comments saying this is difficult. I love how we all assimilate problems differently and what is hard to some is straightforward to others and vice versa - because best believe there are some problems I could never solve in a 45 minute interview that are so called medium or even easy 😂.
    Which is why as much as we all grind leetcode we can't afford to ignore the amount of good fortune that needs to be present for us to land jobs at top firms

    • @zweitekonto9654
      @zweitekonto9654 5 หลายเดือนก่อน +3

      The logic building is medium. But implementation is definitely hard. Too many moving parts and variables to keep track of to come up with a full working solution without skipping a meal.

    • @bouzie8000
      @bouzie8000 5 หลายเดือนก่อน

      I agree tbh@@zweitekonto9654

  • @rafael84
    @rafael84 5 หลายเดือนก่อน

    Javascript version:
    function mostBooked(n, meetings) {
    const available = new MinPriorityQueue({
    compare: (a, b) => a - b
    });
    for (let i = 0; i < n; i++) available.enqueue(i);
    const used = new MinPriorityQueue({
    compare: (a, b) => a[0] - b[0] || a[1] - b[1]
    });
    const count = new Array(n).fill(0);
    meetings.sort((a, b) => a[0] - b[0]);
    meetings.forEach(([start, end]) => {
    while (used.size() > 0 && start >= used.front()[0]) {
    const [, room] = used.dequeue();
    available.enqueue(room);
    }
    if (available.size() > 0) {
    const room = available.dequeue();
    used.enqueue([end, room]);
    count[room] += 1;
    } else {
    const [earliestEnd, room] = used.dequeue();
    used.enqueue([earliestEnd + (end - start), room]);
    count[room] += 1;
    }
    });
    return count.indexOf(Math.max(...count));
    }

  • @yang5843
    @yang5843 5 หลายเดือนก่อน +1

    My boilerplatey Java solution, beats 23%
    class Solution {
    public int mostBooked(int n, int[][] meetings) {
    Map map = new HashMap();
    Queue queue3 = new PriorityQueue( (a,b) -> a.getValue() == b.getValue() ? a.getKey() - b.getKey() : b.getValue() - a.getValue());

    Arrays.sort(meetings,(a,b)->a[0]==b[0]?a[1]-b[1]:a[0]-b[0]);

    Queue queue1 = new PriorityQueue( (a,b) -> a[0]==b[0]?a[1]-b[1]: a[0] - b[0] );

    Queue queue2 = new PriorityQueue();
    for (int i=0;i

  • @justsurajp
    @justsurajp 5 หลายเดือนก่อน

    the c++ version, with the "long long"s is a nuisance 🥲