L8. Non Overlapping Intervals | Greedy Algorithms Playlist

Поделиться
HTML-код
  • Опубликовано: 25 май 2024
  • Find problem link, notes under Step 12: takeuforward.org/strivers-a2z...
    Follow me on socials: linktr.ee/takeUforward

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

  • @socify4410
    @socify4410 Месяц назад +22

    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 🥰

  • @devprakash7166
    @devprakash7166 27 дней назад +3

    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;
    }

  • @hakunamatata-nl4js
    @hakunamatata-nl4js Месяц назад +2

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

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

    Great work pro I hope you are doing extremely well ❤

  • @huungryyyy
    @huungryyyy 15 дней назад

    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 .

  • @Akash-Bisariya
    @Akash-Bisariya Месяц назад

    Waiting for this series ❤❤

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

    Wait is finally over now 😊😊

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 29 дней назад

    thanks

  • @Dsa_kabaap
    @Dsa_kabaap Месяц назад +1

    Sir please start making videos on strings and stacks

  • @prateek4279
    @prateek4279 Месяц назад +4

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

  • @kshitijjha6737
    @kshitijjha6737 Месяц назад +1

    Understood

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

    nice

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 16 дней назад

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

  • @ITwithIT
    @ITwithIT 14 дней назад

    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 9 дней назад

      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.

  • @surbhigupta5777
    @surbhigupta5777 29 дней назад

    US

  • @RachitKala-cp4uh
    @RachitKala-cp4uh 3 часа назад

    Understood