Meeting Rooms - Leetcode 252 - Python

Поделиться
HTML-код
  • Опубликовано: 2 фев 2025

Комментарии • 53

  • @syeds6789
    @syeds6789 3 года назад +91

    Thanks for the LC premium workaround!

  • @matthewtang1490
    @matthewtang1490 3 года назад +84

    This guy saving us all with the lifehack!

  • @Gnaneshh
    @Gnaneshh 3 года назад +12

    Glad I found this gem of a channel.

  • @hankim1083
    @hankim1083 2 года назад +7

    You are a hero we do not deserve, but desperately need.

  • @dorondavid4698
    @dorondavid4698 3 года назад +25

    Teaching us AND saving us money...double whammy!

  • @yossarian2909
    @yossarian2909 2 года назад +9

    You explain it so lucidly.. makes me kick myself that I couldnt think of that!! haha.. thank you so much for inspiring us to improve

  • @symbol767
    @symbol767 2 года назад +4

    Thanks man, just wanted to make sure my solution was good, and it was the same as yours. Liked!

  • @elijaghab7162
    @elijaghab7162 3 года назад +41

    Who are you? You have all these excellent videos, but I am interested in learning why you aren’t working as a software engineer. Could you make videos about yourself? I’m sure other people are curious as well

    • @NeetCode
      @NeetCode  3 года назад +31

      I hope to answer all of the above questions in the very near future 🙂

    • @impostorX
      @impostorX 2 года назад +5

      @@NeetCode i believe you can have your answer now)

    • @studyaccount794
      @studyaccount794 2 года назад +7

      @@NeetCode Man you did it. Really inspiring journey. So happy for you!!

  • @demonsnails
    @demonsnails 3 месяца назад +1

    "I don't know how they can get away with doing that" - proceeds to do it himself as well 😂

  • @MsThinkmoney
    @MsThinkmoney Год назад +5

    I actually got this question during my interview with Meta!

    • @emachine003
      @emachine003 5 месяцев назад

      God I hope this is what I get

    • @danieldsouza2657
      @danieldsouza2657 3 месяца назад +1

      @@emachine003 Prob not unfortunately, the times have changed

    • @OWZook
      @OWZook 3 месяца назад

      @@danieldsouza2657 yeah theyre gonna be giving hards and meds only

    • @2NormalHuman
      @2NormalHuman Месяц назад

      this is too easy for Meta, no?

  • @kirillzlobin7135
    @kirillzlobin7135 Год назад

    Maaan you are amazing!!!

  • @mruduladdipalli5417
    @mruduladdipalli5417 2 года назад

    thanks for the lintcode 🔥

  • @yatish23
    @yatish23 3 года назад +3

    You can you a heap for this to run in linear time... Just start adding it based on the end time... So you'll only have to check the top most value... If it's greater just add it to the. Heap.. else pop it. And push the new value.
    Return true or false based on this?

    • @YeetYeetYe
      @YeetYeetYe 2 года назад +5

      Popping and adding to a heap takes log(n) time, worst case we need to add everything to the heap (ie: there are no conflicts) so that is n*log(n)

  • @satraprathore5349
    @satraprathore5349 2 месяца назад

    Can we do by sorting by end time? Logic: Arrabge them by end and then see if anyone's end time is overlapping with the next one's starting time?

  • @zbclark
    @zbclark 3 года назад +2

    Great video! Why is it nlog(n) ?

    • @JasonKim1
      @JasonKim1 3 года назад

      Sorting is n log(n)

    • @nedimaylamaz5604
      @nedimaylamaz5604 2 года назад

      @@JasonKim1 How do we measure the sorting is n log(n)

    • @rrd
      @rrd 2 года назад +1

      @@nedimaylamaz5604 There are several sorting algorithms. The most efficient ones like Merge Sort has n*log(n) time complexity. Built-in sorting functions most likely use these algorithms and thus have n*log(n) time complexity

  • @asicfps
    @asicfps 7 месяцев назад

    wouldn't we be able to keep track of the total time spent in meetings and the earliest and latest starting and ending times, then compare to see if the total time is less than the latest-earliest? This would be an O(n) solution, i'm unsure if there's some edge case that i'm missing or something

    • @aceofspades-s5o
      @aceofspades-s5o 4 месяца назад

      Won't work for examples with large gaps between meetings ie. [1,5] [2, 5] [100, 101]

  • @PedanticAnswerSeeker
    @PedanticAnswerSeeker 10 месяцев назад

    Is there a way to do this without sorting?

  • @funtalk4083
    @funtalk4083 3 года назад +1

    Can you please make video on leetcode problem Predict the winner.

  • @MP-ny3ep
    @MP-ny3ep 6 месяцев назад

    Neetcode & Lintcode FTW

  • @raminanushiravani9524
    @raminanushiravani9524 Год назад

    first of, your explanations are amazing! and q, shouldn't it be, i1.end >= i2.start ?

    • @thericjaw
      @thericjaw Месяц назад

      Late response but in this problem if the end time and start time are equal it doesn't count as a conflict

  • @algorithmo134
    @algorithmo134 3 года назад

    Do more of this!!!!

  • @sambailor
    @sambailor 4 месяца назад

    It made more sense for me to store the last meeting's end time, and making that the next possible start time.
    This is how I solved it:
    class Solution:
    def canAttendMeetings(self, intervals: List[Interval]) -> bool:
    intervals.sort(key=lambda i: i.start)
    start = 0
    for i in intervals:
    if i.start < start:
    return False
    else:
    start = i.end
    return True

  • @hebrewleetcode8067
    @hebrewleetcode8067 Год назад

    what if we sort the intervals by ending times? will that work?

    • @hyperboliq
      @hyperboliq 7 месяцев назад

      I tried it and it works

    • @hyperboliq
      @hyperboliq 7 месяцев назад

      en.wikipedia.org/wiki/Interval_scheduling#:~:text=The%20greedy%20algorithm%20can%20be%20executed%20in%20time%20O(n%20log%20n)%2C%20where%20n%20is%20the%20number%20of%20tasks%2C%20using%20a%20preprocessing%20step%20in%20which%20the%20tasks%20are%20sorted%20by%20their%20finishing%20times.

  • @bigrat5101
    @bigrat5101 2 года назад

    I ran this code you had in your video, but it did not pass test case [[7,10],[2,4]]

    • @darhkz3900
      @darhkz3900 2 года назад +2

      if you sorted the intervals first it should work

  • @aaron7c
    @aaron7c 4 месяца назад

    Wouldn't it be more efficient to build a tree based on start times. The solution would only be log n time complexity.

  • @rishirajpaulchowdhury2874
    @rishirajpaulchowdhury2874 2 месяца назад

    I ran this linear O(n) approach and it worked both in neetcode and lintcode
    int n=intervals.size();
    for(int i=0;i intervals[i+1].start && intervals[i].start

  • @akumasdeception
    @akumasdeception 2 года назад

    The description for this question on leetcode is terrible. The examples don't help at all.

  • @jolokiachili6589
    @jolokiachili6589 6 месяцев назад

    i dont think this would pass by an interviewer, as you should probably sort without using a built in library.

  • @rlavanya8447
    @rlavanya8447 3 года назад +1

    New 21 please

  • @sK0pe-d9b
    @sK0pe-d9b 2 месяца назад

    Can you not make a linear solution:
    public boolean canAttendMeetings(List intervals) {
    if(intervals.size() < 2) {
    return true;
    }
    for(int i = 1; i < intervals.size(); i++) {
    int maxStart = Math.max(intervals.get(i - 1).start, intervals.get(i).start);
    int minEnd = Math.min(intervals.get(i - 1).end, intervals.get(i).end);
    if(maxStart < minEnd) {
    return false;
    }
    }
    return true;
    }

  • @Rohit-qp1ye
    @Rohit-qp1ye 3 года назад +2

    Make meetingr room 2 bro

    • @NeetCode
      @NeetCode  3 года назад +3

      ruclips.net/video/FdzJmTCVyJU/видео.html

  • @MichaelShingo
    @MichaelShingo Год назад

    oh that's how you sort a list of objects

    • @hyperboliq
      @hyperboliq 7 месяцев назад

      ikr - so useful and clutch

  • @D-zigi
    @D-zigi 10 месяцев назад

    won't this linear approach work?
    def canAttendMeetings(intervals):
    start = min(intervals, key=lambda x:x[0])[0]
    end = max(intervals, key=lambda x:x[1])[1]
    expected_t = sum(x[1]-x[0] for x in intervals)
    made_t = end - start
    return made_t >= expected_t

  • @spiffylogic
    @spiffylogic Год назад

    It's pronounced "tuh pl" as in quintuple.