L8. Non Overlapping Intervals | Greedy Algorithms Playlist

Поділитися
Вставка
  • Опубліковано 28 вер 2024
  • Find problem link, notes under Step 12: takeuforward.o...
    Follow me on socials: linktr.ee/take...

КОМЕНТАРІ • 23

  • @socify4410
    @socify4410 4 місяці тому +46

    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 🥰

  • @hakunamatata-nl4js
    @hakunamatata-nl4js 3 місяці тому +3

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

  • @prateek4279
    @prateek4279 3 місяці тому +7

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

  • @huungryyyy
    @huungryyyy 2 місяці тому +5

    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 .

  • @Dsa_kabaap
    @Dsa_kabaap 4 місяці тому +1

    Sir please start making videos on strings and stacks

  • @kshitijjha6737
    @kshitijjha6737 4 місяці тому +1

    Understood

  • @subee128
    @subee128 Місяць тому

    thanks

  • @ITwithIT
    @ITwithIT 2 місяці тому

    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 2 місяці тому +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 9 днів тому

      @@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 ?

  • @shashankvashishtha4454
    @shashankvashishtha4454 2 місяці тому

    understood

  • @jotsinghbindra8317
    @jotsinghbindra8317 3 місяці тому

    nice

  • @surbhigupta5777
    @surbhigupta5777 3 місяці тому

    US

  • @UECAshutoshKumar
    @UECAshutoshKumar 11 днів тому +1

    Thank you

  • @RachitKala-cp4uh
    @RachitKala-cp4uh 2 місяці тому

    Understood

  • @ahmedyasser4928
    @ahmedyasser4928 4 місяці тому +2

    Great work pro I hope you are doing extremely well ❤

  • @devprakash7166
    @devprakash7166 3 місяці тому +4

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

  • @cleweric
    @cleweric Місяць тому

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

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 3 місяці тому

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

  • @shivrajkumar4000
    @shivrajkumar4000 4 місяці тому

    Wait is finally over now 😊😊

  • @Akash-Bisariya
    @Akash-Bisariya 4 місяці тому

    Waiting for this series ❤❤

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 3 місяці тому

    thanks