Merge Overlapping Intervals | Q13 | Love Babbar DSA sheet | Amazon | Google
Vložit
- čas přidán 3. 11. 2020
- #coding #competitiveprogramming #interviewquestions #dsaseries
In this video I have explained the 13th problem.
Code for O(1) space complexity-- www.geeksforgeeks.org/merging... (refer to below section in this link).
Love Babbar DSA sheet : drive.google.com/file/d/1FMdN...
Hope you like it. If have any doubt then just comment down below.
LIKE | SHARE | SUBSCRIBE
l love your accent bro.God bless you.keep teaching
You are doing a great work .
It will help many students.
Keep uploading bro.
You guys are doing well 🔥
Your explanation is too good👍
Thank you so much fo these videos. Great explanation indeed
Recently I started watching your videos and they are helping alot .
You are doing great work.
Your way of explaination is so good.
Keep going bro❤
awesome bro awesome!!
Explanation is so good! Thank you for the video!!
You're very welcome!
Nice explaination.😊
💢💢Great job💢💢
Your explanation is too Good Bro! Thanks Broo keep Uploading coding video .
Good Explane
Kudos🙌
Bhai pls reply krdena kabhi kabhi aisa lgta hai ki main itni mehnat kr rhahu sab seekh rha hu par yh kuch din baad concept ud jaate h thode thode dimaag se aisa lgta hai I won't be able to code when situation comes pls tell What to do..
brother try to code self and also do the dry run using pen paper
Super easy solution ❤
"Let's Strart " The swag.... 🙆♀️
thanks
Thank you for the effort u have put to explain all questions on the sheet. Your explanation is very good too. Hope u make it to 100M subscribers! All the best!
Hehe tht was exactly which I was solving
First parametere ko ghusa denge 😂😂😂😂😂😂😂 7:24 sorry bro dirty mind
bhaiya saara code description m de dia kro, plz have a humble request
What is wrong in my code? I did it with second approach.
vector merge(vector& intervals) {
int size = intervals.size();
int idx = 0;
int i = 1;
for(;i
Thanks for explanation ,
Bro i had a question , that this question is given on leetcode in which a vector of vector is passed to the function(in which we have to write merge interval algo) with all inputs in it , but how can we sort vector of vector ?
i had to created a different vector of pair and than sorted it
same method sort(v,.begin,v.end());
Bro you are explaining code very nicely and your original accent is very good. So,please don't copy someone else accent the way that guys speaks whom you are trying to copy is really very irritating , so,try to continue in your normal and original accent that is already very good, I guess you got my point , don't get offended consider this as positive review
bhai vector of pairs nahi dia rehta vector of vector dia rehta he input ! usme direct sort kese lagaoge ! pehle 2d array se pair ke array me copy karna padta he phir sort hota he !!!
Vector of vector ko agar sort() function se karoge toh first parameter se sort ho jaega
@@CodeLibrary bhai comparator nhi likhna pdega uske lie ???
bro,also upload for JAVA 😐😐
getting confused with index and i
Please make either in complete english or complete hindi. It's painful to listen to hinglish.
bhai tu sort krna btaya hi nhi isme
please provide the code in java also
public int[][] merge(int[][] intervals){
if(intervals.length == 1) return intervals;
Arrays.sort(intervals, (a,b) -> Integer.compare(a[0], b[0]));
Stack stack = new Stack(); // we can use LinkedList or ArrayList also
stack.push(intervals[0]);
for(int[] arr : intervals){
int lo = arr[0], up = arr[1];
if(stack.peek()[1] >= lo ) stack.peek()[1] = Integer.max(up, stack.peek()[1]);
else stack.add(arr);
}
return stack.toArray(new int[stack.size()][]);
}
// O(1) space solution
public int[][] merge(int[][] intervals){
if(intervals.length == 1) return intervals;
Arrays.sort(intervals, (a,b) -> Integer.compare(a[0], b[0]));
int endIdx = 0;
for(int[] arr : intervals){
int lo = arr[0], up = arr[1];
if(intervals[endIdx][1] >= lo)
intervals[endIdx][1] = Integer.max(up, intervals[endIdx][1]);
else{
endIdx += 1;
intervals[endIdx] = arr;
}
}
int[][] ans = new int[endIdx+1][2];
for(int i=0;i
Bhai ye sab take u forward channel mai solve kia gaye problems hai.
Code for the 2nd method:
#include
using namespace std;
int main(){
int n;
cin>>n;
vector v;
for(int i=0;i>x>>y;
v.push_back({x,y});
}
sort(v.begin(),v.end());
int index = 0;
for(int i=1;i= v[i].first){
v[index].second = max(v[index].second,v[i].second);
v[index].first = min(v[index].first,v[i].first);
}
else {
index++;
v[index] = v[i];
}
}
cout
great sir ji
great
Great explanation but bro please teach in hindi Bcoz your english is not good