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 🥰
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 .
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; }
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
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...
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
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.
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.
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
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 🥰
log pdhte pdhte aise emotional kyu ho jaate hai lmaoo
the way you find relation with other problems is amazing. thank you!
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 .
You have laid a strong foundation for many CS students in their coding journey!
since code was not on website here is it for everyone:
class Solution {
public:
static bool comp(vector&a,vector&b){
return a[1]
thanks
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;
}
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
Great work pro I hope you are doing extremely well ❤
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...
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
Understood 😊
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.
Wait is finally over now 😊😊
Great Striver !
Thank you
Waiting for this series ❤❤
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;
}
};
Sir please start making videos on strings and stacks
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
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??
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.
@@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 ?
A short meeting in terms of length might end later than a longer meeting, reducing the time available for subsequent meetings.
understood
How you got an idea of n meetings for this problem???
UNDERSTOOD;
Understood
thanks
this problem should be redundant if I solved last n meetings in room
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
we can use without the vector of pair
nice
US
thanks
Understood
Understood