Non-overlapping Intervals
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.
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]
Thanks, ma'am for the simple explanation. I was stuck with the implementation for a long time.
Very very very good explanation! Thank you so much!!!
ek to itni cute ,uper se coder ...haaye jaan hi logi kya 😇🥰❤❤
Thanks for explaining in this very intutive way
Thanks. Very good explanation.
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 .
Amazing Explanation !!
Love (u) the way u teach ❤❤
great explanation
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;
}
tysm nicely explained
Thanks a lot
Thank you diiiiiiii
yrrr tum kitni cute ho...dayum beauty with brains....
She wants me
got it
in your first example you said intervals are not overlapping but they are overlapping so please modify that example otherwise students will get confused
See whole video
Feeling Laughs with proverb:" Killing 1 bird with 2 stones "
Cruel 😖
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
Yes Milind, thanks for pointing it out, took the wrong example : )
abe saale milind jab clear ho gya tha tujhe toh comment karne ki kyu khujli hori
mam are you alive 🙄
are u in a hurry to go somewhere why are u explaining it very fast focus on that
😮