Non-overlapping Intervals

Sdílet
Vložit
  • čas přidán 6. 10. 2021
  • Given an array of intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping
    Input: intervals = [[1,2],[2,3],[3,4],[1,3]]
    Output: 1
    Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping.
    Example 2:
    Input: intervals = [[1,2],[1,2],[1,2]]
    Output: 2
    Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.
    Input: intervals = [[1,2],[2,3]]
    Output: 0
    Explanation: You don't need to remove any of the intervals since they're already non-overlapping.

Komentáře • 28

  • @mriduljain5801
    @mriduljain5801 Před 11 měsíci +2

    in both the cases there is one thing common to be pointed out that both cases that array should be sorted according to ending points
    class Solution {
    public:
    static bool comp(vector a, vector b){
    return a[1]

  • @tridibeshmisra9426
    @tridibeshmisra9426 Před 4 měsíci

    Thanks, ma'am for the simple explanation. I was stuck with the implementation for a long time.

  • @MitrankShah
    @MitrankShah Před rokem +6

    Very very very good explanation! Thank you so much!!!

  • @JohnWickea
    @JohnWickea Před rokem

    ek to itni cute ,uper se coder ...haaye jaan hi logi kya 😇🥰❤❤

  • @ajaybabupatel1665
    @ajaybabupatel1665 Před rokem

    Thanks for explaining in this very intutive way

  • @GauravSingh-ku5xy
    @GauravSingh-ku5xy Před 2 lety +1

    Thanks. Very good explanation.

  • @satyamshukla1418
    @satyamshukla1418 Před 2 lety

    The leetcode description was not very clear to me so i misunderstood and applied Lis which ran few test cases but this was very helpful .

  • @user-le3pr5mr1j
    @user-le3pr5mr1j Před 10 měsíci

    Amazing Explanation !!

  • @manasa1864
    @manasa1864 Před rokem

    Love (u) the way u teach ❤❤

  • @amanshujaiswal4728
    @amanshujaiswal4728 Před rokem

    great explanation

  • @Raj10185
    @Raj10185 Před rokem

    very good explanation my code for same :-
    sort(intervals.begin(),intervals.end());
    int n = intervals.size();
    vector temp(2,0);
    temp[0]= intervals[0][0];
    temp[1]= intervals[0][1];
    int count =0;

    for(int i = 1 ; i < n ; i++)
    {


    int currst = intervals[i][0];
    int currend = intervals[i][1];


    if( currst < temp[1]) //overlapping
    {


    count++;


    //check for full merge overlapping then update the temp
    if(currst > temp[0] && currend < temp[1])
    {

    temp[0]= currst;
    temp[1]=currend;

    }






    }
    else //non overlapping just update the temp
    {

    temp[0]= currst;
    temp[1]=currend;



    }







    }


    return count;



    }

  • @jayanthotwani6200
    @jayanthotwani6200 Před rokem

    tysm nicely explained

  • @raushankumar6993
    @raushankumar6993 Před rokem

    Thanks a lot

  • @ashvinkumhar5819
    @ashvinkumhar5819 Před 2 lety

    Thank you diiiiiiii

  • @samyakjain7422
    @samyakjain7422 Před rokem +1

    yrrr tum kitni cute ho...dayum beauty with brains....

  • @shoryasinghal5241
    @shoryasinghal5241 Před rokem +1

    got it

  • @ishikaagrawal5648
    @ishikaagrawal5648 Před 9 měsíci +1

    in your first example you said intervals are not overlapping but they are overlapping so please modify that example otherwise students will get confused

  • @tridevthakur7711
    @tridevthakur7711 Před rokem

    Feeling Laughs with proverb:" Killing 1 bird with 2 stones "

  • @MilindGupta
    @MilindGupta Před 2 lety +2

    The first example which u took [1,5],[3,8],[10,15]. Here 3 is actually overlapping but u told it's not
    Anyways u cleared in further video

  • @shatnuu_
    @shatnuu_ Před 2 měsíci +1

    mam are you alive 🙄

  • @naveenkumarkota2090
    @naveenkumarkota2090 Před 6 měsíci

    are u in a hurry to go somewhere why are u explaining it very fast focus on that