L8. Non Overlapping Intervals | Greedy Algorithms Playlist

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

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

  • @socify4410
    @socify4410 7 หลายเดือนก่อน +61

    Whenever your heart is broken
    Don't ever forget you're golden
    I will find a light in your soul
    I'll be there
    Never leaving you in the darkness
    Even when you're out of focus
    I will be the light in your life
    You'll see clear
    I'll be your inspiration
    'Cause I know that you'll do just what you're told
    I'll be your hard-earned temptation, yeah
    'Cause I know that you'll make it on your own
    Baby, you can count on me now
    When you're falling down, down, down
    I will find a light in your soul
    I'll be there
    Leaving you alone is the hardest
    Even when you're out of focus
    I will be the light in your life
    You'll see clear
    I'll be your inspiration
    'Cause I know that you'll do just what you're told
    I'll be your hard-earned temptation, yeah
    'Cause I know that you'll make it on your own
    I'll be your inspiration
    'Cause I know that you'll do just what you're told
    I'll be your hard-earned temptation, yeah
    'Cause I know that you'll make it on your own
    Yeah, on your own
    -----------------------------------------------------
    yes you are our inspiration striver 🥰

    • @ManaswiSingh-kr5yz
      @ManaswiSingh-kr5yz 13 วันที่ผ่านมา +2

      log pdhte pdhte aise emotional kyu ho jaate hai lmaoo

  • @hakunamatata-nl4js
    @hakunamatata-nl4js 7 หลายเดือนก่อน +7

    the way you find relation with other problems is amazing. thank you!

  • @huungryyyy
    @huungryyyy 6 หลายเดือนก่อน +9

    as soon as I listened n meetings in a room I rushed back to questions. I was struggling with my approach but as soon I heard the title n meetings I got the solution .

  • @Batman54934
    @Batman54934 19 วันที่ผ่านมา

    You have laid a strong foundation for many CS students in their coding journey!

  • @prateek4279
    @prateek4279 6 หลายเดือนก่อน +10

    since code was not on website here is it for everyone:
    class Solution {
    public:
    static bool comp(vector&a,vector&b){
    return a[1]

  • @devprakash7166
    @devprakash7166 6 หลายเดือนก่อน +8

    I sorted the array with respect to start time in ascending order. While traversing, if start_time of the current interval is greater than end time of the previously selected interval, then we would need to remove one interval, and we would remove that interval whose end time is lesser. it works .
    bool compare(vector& a, vector& b) {
    if ( a[0] < b[0]) return true;
    if ( a[0] == b[0]) {
    return a[1] < b[1];
    }
    return false;
    }
    int eraseOverlapIntervals(vector& intervals) {
    int n = intervals.size();
    if ( n == 1) return 0 ;
    sort(intervals.begin(), intervals.end(), compare);
    int count = 0 , prevEndTime = INT_MIN;
    for( int i = 0 ; i < n ; ++i) {
    if( intervals[i][0] < prevEndTime) {
    count++;
    prevEndTime = min(prevEndTime, intervals[i][1]);
    } else {
    prevEndTime = intervals[i][1];
    }
    }
    return count;
    }

    • @prateekverma2597
      @prateekverma2597 9 วันที่ผ่านมา

      code will run even without the prevEndTime = min(prevEndTime, intervals[i][1]); this line
      example :
      class Solution {
      static bool comp(pair a , pair b){
      return a.second < b.second;
      }
      public:
      int eraseOverlapIntervals(vector& intervals) {
      vectorv;
      for(int i=0;i

  • @ahmedyasser4928
    @ahmedyasser4928 7 หลายเดือนก่อน +2

    Great work pro I hope you are doing extremely well ❤

  • @diksha683
    @diksha683 14 วันที่ผ่านมา

    i divided the intervals arr into start and end arr ...only one thing was incorrect in my code....otherwise i was able to solve the ques by myself....just wrote the code of n meetings and returned n-cnt....i am so happy...this is the first time probably i was able to do it by myself...the moment u said rev of n meetings i got it...

  • @DurgaSivaLokeshTelaprolu
    @DurgaSivaLokeshTelaprolu 17 วันที่ผ่านมา

    we could simply do this instead
    class Solution:
    def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
    intervals.sort(key = lambda x: x[1])
    removalCount = 0
    lastEndTime = intervals[0][1]
    for i in range(1, len(intervals)):
    if intervals[i][0] < lastEndTime:
    removalCount += 1
    else:
    lastEndTime = intervals[i][1]
    return removalCount

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

    Understood 😊

  • @1499divya
    @1499divya 2 หลายเดือนก่อน

    we can see this as N meetings in a rooms where we have to tell minimum meetings we cannot conduct because they have a overlap. We tell how many min meetings cannot happen while max meetings happen.

  • @shivrajkumar4000
    @shivrajkumar4000 7 หลายเดือนก่อน

    Wait is finally over now 😊😊

  • @apmotivationakashparmar722
    @apmotivationakashparmar722 2 หลายเดือนก่อน

    Great Striver !

  • @UECAshutoshKumar
    @UECAshutoshKumar 3 หลายเดือนก่อน +1

    Thank you

  • @Akash-Bisariya
    @Akash-Bisariya 7 หลายเดือนก่อน

    Waiting for this series ❤❤

  • @shreyxnsh.14
    @shreyxnsh.14 2 หลายเดือนก่อน

    Same code:
    bool comp(vector &a, vector &b){
    return a[1] < b[1];
    }
    class Solution {
    public:
    int eraseOverlapIntervals(vector& intervals) {
    if(intervals.size() == 1){
    return 0;
    }
    //sort by ending time:
    sort(intervals.begin(), intervals.end(), comp);
    int count = 0, last = intervals[0][1];
    for(int i=1;i= last){
    last = intervals[i][1];
    }else
    count++;
    }
    return count;
    }
    };

  • @Dsa_kabaap
    @Dsa_kabaap 7 หลายเดือนก่อน +1

    Sir please start making videos on strings and stacks

  • @HARSHRAJ-gp6ve
    @HARSHRAJ-gp6ve 2 หลายเดือนก่อน

    class Solution {
    public:
    vector merge(vector& intervals) {

    int n=intervals.size();
    int p,q;
    vector visited(n);
    vector harsh;
    sort(intervals.begin(),intervals.end());
    for(int i=0;i

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

    Can anyone explain for this problem as well as for N meetings problem, why are we sorting based on end time and not on the length of the interval??

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

      Yeah I had the same doubt, it can be cleared with an example:
      Lets say we have [(0,3),(2,4),(3,6)]
      According to you, if we sort by the length of the intervals, we'll complete (2,4) first - effectively blocking (0,3) and (3,6)
      Instead if we sort by end times, we'll get (0,3)(3,6) as valid non clashing intervals.
      Sorting based on length of the intervals doesn't give an optimal substructure.

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

      @@yashmundada2483 but in this question if i sort based on start time it will work but in the n meeting it wont can u figure out why ?

    • @bhavika6347
      @bhavika6347 20 วันที่ผ่านมา +1

      A short meeting in terms of length might end later than a longer meeting, reducing the time available for subsequent meetings.

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

    understood

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 6 หลายเดือนก่อน

    How you got an idea of n meetings for this problem???

  • @DeadPoolx1712
    @DeadPoolx1712 2 หลายเดือนก่อน

    UNDERSTOOD;

  • @kshitijjha6737
    @kshitijjha6737 7 หลายเดือนก่อน +1

    Understood

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 6 หลายเดือนก่อน

    thanks

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

    this problem should be redundant if I solved last n meetings in room

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

    class Solution {
    public:
    bool static cmp(pair &a, pair &b) {
    return a.second < b.second;
    }
    int eraseOverlapIntervals(vector& intervals) {
    vector res;
    for (int i = 0; i < intervals.size(); i++) {
    res.push_back({intervals[i][0], intervals[i][1]});
    }
    sort(res.begin(), res.end(), cmp);
    int cnt = 0;
    int first = res[0].second;
    for (int i = 1; i < intervals.size(); i++) {
    if (first

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

      we can use without the vector of pair

  • @jotsinghbindra8317
    @jotsinghbindra8317 6 หลายเดือนก่อน

    nice

  • @surbhigupta5777
    @surbhigupta5777 6 หลายเดือนก่อน

    US

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

    thanks

  • @RachitKala-cp4uh
    @RachitKala-cp4uh 5 หลายเดือนก่อน

    Understood

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

    Understood