Please watch the new video which covers it in more depth, and also prints it: kzbin.info/www/bejne/f5bbf2lmoJtloNE How is the new thumbnail, should we keep it for all ? As always, if you understand, make sure you drop "understood" in the comment section, if you have doubt, drop that in, will revert :) . If you appreciate the channel's work, you can join the family: kzbin.info/door/JskGeByzRRSvmOyZOz61igjoin
@amankrsingh4 жыл бұрын
Old one was very Good
@pranshukumarsingh76534 жыл бұрын
Understood
@vinayduggal24334 жыл бұрын
@take U forward Pls. Reply striver bro . Bro I am currently coding in python but as u say in ur video that 85 percent people do coding in c++. And also some companies doesn't allow python during interview . May I go for c++(stl) or continue in python. I am now in final year of b.tech
@VijayKumar-bk9bq4 жыл бұрын
sir make a video in hindi...pleade sir..
@vaibhavsethia704 жыл бұрын
Understood
@sandeepnallala483 жыл бұрын
you are not striver , you are SAVIOUR : ) love ur lectures brother : )
@mrsmurf911 Жыл бұрын
(a[i]==b[j] and (b[j]==c[k]))
@paridhijain70622 жыл бұрын
this video is so well explained and I got each and every point of it. Referring Striver sheet along with this video. Thank you striver for making such wonderful content for us.
@GaneshBhutekar-nu1gdАй бұрын
i did the same thing without any tutorial now i am feeling confident
@vaibhavyadav178711 ай бұрын
You don't know how much you're helping us..... God bless you brother....
@gouravmallick273 жыл бұрын
this was the most efficient explanation, thanks, sir.
@tanmaychandra94344 жыл бұрын
Great effort Man we can learn alot from you there are several people who keep their all learnings within themselves but you came out and kept on sharing your knowledge . Great respect man.
@aditya-bl5xh4 жыл бұрын
Want to be as dedicated as he is, he got a job then also he's helping us, great! Thank you so much bro
@GauravKumar-bk7hh3 жыл бұрын
bro mujhe coding se thora dar lagta hai. agar main koi problem karne baithta hue to logic click hi nahi hota. main bhi chahata hue ki apna 100% dun per wo interest nahi aa pata
@sannidhayvashal98063 жыл бұрын
@@GauravKumar-bk7hh Why are you coding then ? If you don't enjoy the process then you are in the wrong field.
@harshupreti15262 жыл бұрын
@@GauravKumar-bk7hh solution samjhne ke baad bhi maza ni aata toh chod de
@viggicodes2 жыл бұрын
I disable ad blocker and watch your videos. Keep up the good work striver !!
@nivedithat47454 жыл бұрын
After watching video halfway through, I thought how lucky the current 2nd years and 3rd years are… they can watch the entire playlist in 10 days and voila!!! ready for cracking companies
@rajeevsingh54534 жыл бұрын
m in 3rd year and m thinking the same for 1st and 2nd year.
@maitrishmandal_31394 жыл бұрын
m in 2nd year and m thinking the same for 1st year.
@ash-gt4 жыл бұрын
m in 1st year and m thinking the same for class 12th
@HARIHaran-ks7wp4 жыл бұрын
@@ash-gt my in womb and thinking the same for previous birth
@pranayreddy58244 жыл бұрын
I am 12th and thinking of 6 year old chintu how lucky he is...😂 just kidding i am b-tech final year
@ifzagul27602 жыл бұрын
Your method to teach is astonishing.
@araragikoyomi71863 жыл бұрын
I solved the brute force using graph by creating components of intervals which are overlapping and finding minimum and maximum range and insert it in the ans
@annawilson38243 жыл бұрын
we are comparing the first interval with itself, can avoid it. O/w, great job!
@vishalm7844 жыл бұрын
I think the brute force approach doesn't require sorting at all and would have time complexity O(n^2). First, we merge all the interval pairs that overlap and add to an array and form a result. Then we do it recursively to find if there's still some more merging possible and if not return the result. But surprisingly this algorithm is faster than the optimal solution mentioned. LeetCode result : Runtime: 2 ms, faster than 99.47% of Java online submissions for Merge Intervals. This is the version I implemented :- public int[][] merge(int[][] intervals) { int n = intervals.length; boolean included[] = new boolean[n]; ArrayList arr = new ArrayList(); for(int i = 0;i
@RahulSharma-jl3xd2 жыл бұрын
@dhananjaysingh36752 жыл бұрын
True ..ths what confused me too.. If intervals are already sorted then why check the remaining list of intervals, if one of the subsequent interval is already found non merging..
@vamshikrishnareddy23132 жыл бұрын
also can be solved by using prefix sum, array between (1, and max), considering edge cases and space
@nishantmohanty21474 жыл бұрын
Bhai apana bahut bhala kama karuchanti. Apana bahut bhala teacher.
@subhamkumar14323 жыл бұрын
Explanation is extremely understandable and convenient:)
@freshcontent37293 жыл бұрын
can you please write the bruteforce cpp code of this which is shown in this video? i tired to implement that approach but getting stuck, please help
@amarjeetkumarsingh733 Жыл бұрын
This is your best explanation I have ever seen
@Aditya-karn94 жыл бұрын
What you are doing is fabulous. I understand every concept that you are teaching. Can you make a video on Closest Palindrome problem, as i don't find any satisfactory video of this problem.
@nehasagar94164 жыл бұрын
Understood🔥....I love ur videos And I loved the previous thumbnail. Thank you so much for helping us with everything ♥️
@arup_creations35453 жыл бұрын
We can also perform the optimised approach in-place. For each merge operation that we perform we can keep a count. We can update the interval 2D vector with the optimal intervals that we get instead of using mergeIntervals. Then we can return the interval from interval.begin() to interval.begin() + count - 1. This way the space complexity will further reduce to O(1). Please let me know your views in this appeoach of mine.
@kirtanprajapati84643 жыл бұрын
Your explanation and code are so pretty much. Thanks a lot, bro
@bhaveshkumar68423 жыл бұрын
Your videos are immensely helpful!
@prateekverma91663 жыл бұрын
Your efforts make my struggles easy, awsm content
@paritoshdadhich29544 жыл бұрын
Thank you bhaiya for making such important videos. More power to you!!
@pratyushgupta3193 жыл бұрын
I think on Line 5 (09:54) We should first check for null and then .length cause if its null, it will throw NullPointerException... but incase of leetcode they will not give null as an input 😅, they usually give the array of size 0.
@sumanshekhar81102 жыл бұрын
Exactly, that will prevent a null pointer
@ayushgupta-ds9fg Жыл бұрын
Ur explaination are next level
@pirangitharun87363 жыл бұрын
I write my codes in java and I came to know many new things after seeing your code. Thank you bro
@ishangujarathi10 Жыл бұрын
Greattt, Understood completely and even coded myself after understanding the logic!!!tysm
@sush98894 жыл бұрын
this course is best ! keep going vikram bhai !
@-CYSAIANUSHA2 жыл бұрын
You are awesom.....very crisp but very very effective....can you make a video on how to solve any problem in front of interviewer effectively...?
@prithvichetty153 жыл бұрын
great video please keep making such videos and also please keep providing the solution and code because its great help.
@aditijain94232 жыл бұрын
In the merge step, you also need to check the new pair's 2nd index if it is less than the first pair's 2nd Index, the merge will not be needed since it lies in the first pair.
@sahilparanjape86022 жыл бұрын
end = Math.max(end, i[1]) checks if the 1st pairs second index(end) is greater than the new pair's second index(i[1]).
@itz_me_imraan022 жыл бұрын
Got the optimized solution in my very first attempt 😌
@boundlesstech52922 жыл бұрын
haha 🤣
@riyadhossain1706 Жыл бұрын
you're videos are awesome................
@saifali-fr2zx3 жыл бұрын
i think we can do this in more efficient way i.e without sorting we follow your 2nd method but without sorting , now we will do same thing again from left to ri8 and then from ri8 to left time complexity will be O(3n)
@dillirajtimalsina2 жыл бұрын
no we cant because in arr[] = a b c: if(a and c get's merged but b doen't with both then in either direction it won't merge a and c) lol
@makelearneasy10503 жыл бұрын
actually i have a doubt in line 11 where auto is used then it should start iterating from first pair if interval vector which is same as the pair in mergedIntervals so how after for loop iterator is pointing to second element of array because in next line it is written it[0]
@bibhasjha34123 жыл бұрын
i have same doubt and if u ever found answer to it kindly plz explain
@innfinityraag76822 жыл бұрын
actually it is not pointing to second element of the array it is pointing of the array the point is in first iteration we are comparing if 3 is greater than 1 or not (in first interval) which is true ...then at end of every iteration temp will set to it and it will point to next element so thats how from second iteration temp[1] is 3 and it[0] is 2
@jatinbhatoya84204 жыл бұрын
u are doin a very good job. well done bro
@kshitijmishra27162 жыл бұрын
this is asked today in my interview guys please take this problem seriously
@TheProblemSolvers382 жыл бұрын
Did you answered it .... ?
@kshitijmishra27162 жыл бұрын
@@TheProblemSolvers38 nah i did not solved this problem
@TheProblemSolvers382 жыл бұрын
@@kshitijmishra2716 Sorry to hear that .... But keep striving ... : )
@infinioda1084 жыл бұрын
Bro ur interview tips are greeeeatttt :)
@atulranjan7943 жыл бұрын
O(nlogn) Time complexity and O(1) space is more efficient vector merge(vector& intervals) { vectorans; sort(intervals.begin(),intervals.end()); ans.push_back(intervals[0]); for(int i=1;i=intervals[i][0]){ int p=ans[ans.size()-1][0]; int q= max(ans[ans.size()-1][1],intervals[i][1]); ans.pop_back(); ans.push_back({p,q}); } else ans.push_back(intervals[i]); } return ans; }
@atulranjan7943 жыл бұрын
@takeyouforward
@Tarun-Mehta3 жыл бұрын
Keep sharing, Thank you very much 🙏🙏
@cinime2 жыл бұрын
Understood! Super awesome explanation as always, thank you very much!!
@krishnabhardwaj980510 ай бұрын
best solution for this problem...........
@stith_pragya2 жыл бұрын
Thank You bro, very well explained>>>>>>>>>>>>>>>>😊😊😊😊😊😊
@raoshnakquadri87312 жыл бұрын
Thank u so much striver for such a nice explanation....
@harshsheth66334 жыл бұрын
This thumbnail is way better but just try to make background light bcoz due to that words are not clear enough...
@SAKSHIKUMARIP2 жыл бұрын
thank you for making wonderful content for us!!!
@notelectrohead Жыл бұрын
Python Code: intervals.sort(key=lambda x: x[0]) merged = [] for interval in intervals: # if the list of merged intervals is empty or if the current # interval does not overlap with the previous, simply append it. if(not merged or merged[-1][1] < interval[0]): merged.append(interval) else: # otherwise, there is overlap, so we merge the current and previous # intervals. merged[-1][1] = max(merged[-1][1],interval[1])
@rajvibagohil67264 жыл бұрын
Very good explanation!! Keep it up!!!
@dadidivya86632 жыл бұрын
Why do we need space complexity in the optimised approach.. I think we can avoid it right.. here's my solution class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals=sorted(intervals) i=1 while(i= intervals[i][0]): max1=max(intervals[i][1],intervals[i-1][1]) intervals[i]=[intervals[i-1][0],max1] intervals.remove(intervals[i-1]) else: i+=1 return intervals By the way.. striver.. thank you so so much.. not only for the videos but also the constant motivation... Have started ur sde sheet.. I know its late.. but I am going to do it...Thanks a lot:-)
@lol22852 жыл бұрын
great video , but dont you think you should focus more on explaining how the "merge" works? I mean once someone understand how to merge two arrays ( figuring out what exactly is a merge in this context ), i think they can figure out "which" elements to merge.
@takeUforward2 жыл бұрын
I am expecting you to know merge sort
@lol22852 жыл бұрын
@@takeUforward I was pointing to what you were explaining at 4:30, "The merging step", i had a little bit of trouble understand how to code that , Is it a variation of merge sort?
@_hulk748 Жыл бұрын
You are great Sir🙏❤✨🙇♂
@Noobgaming-tc1jo4 жыл бұрын
ary dislike chordo u iz riieeaaal leegend 🚩😁
@yeswanthh50682 жыл бұрын
Thank you understood 🙂🙂💚
@sumanthakur2014 жыл бұрын
Please upload more such videos... It's helping. Thank you :)
@manishmalik.3 жыл бұрын
You are welcome roll no. 33
@pawanlok17762 жыл бұрын
thank you for making the playlist,, it really helps me a lot..
@sajramkisho99913 жыл бұрын
i have modified the java code.....if anyone feel struck....look below..... class Solution { public int[][] merge(int[][] intervals) { if(intervals.lengthInteger.compare(arr1[0],arr2[0])); Listres=new ArrayList(); int[] current_interval=intervals[0]; res.add(current_interval); for(int[] i:intervals){ int current_begin=current_interval[0]; int current_end=current_interval[1]; int next_begin=i[0]; int next_end=i[1]; if(current_end>=next_begin){ current_interval[1]=Math.max(current_end,next_end) ; } else{ current_interval=i; res.add(current_interval); } } return res.toArray(new int[res.size()][]); } }
@abhishekk12312 жыл бұрын
You're a great teacher!
@ameyakaranjkar93594 жыл бұрын
Wonderful walkthrough brother! The only thing is, I am not able to develop my intuition for why we sort based on start time! 1. What if we sorted based on end time? (Can we develop another algorithm in this case) 2. What if we sorted based on start time but in decreasing order? Can you please throw some light on this as this might help us crack variation problems! Thanks in advance! Love your work. 🙌🙏😊
@giri1982 Жыл бұрын
Thanks for the posting!
@ashishsinha88934 жыл бұрын
Love you bro one thing I would like to know everyday you r uploading
@nikitajaiswal91123 жыл бұрын
Wow amazing😍🤩.... Thank you so Much 😊
@AhmedAdel-xg1cm3 жыл бұрын
thank you so mush for this amazing explanation, u are my hero :)
@sonaalmahadani6512 жыл бұрын
he made it look so easy damm!!!!!
@hackpiece30944 жыл бұрын
Hey Brother! You are doing a great work :) However I would like to point out that the merging result can be put back in the original vector or or data structure. That would make it constant space. ❤️
@takeUforward4 жыл бұрын
Not it does not makes it, since you are first taking into some other ds
@hackpiece30944 жыл бұрын
@@takeUforward Brother, will you please have a look on the last implementation of the link? www.geeksforgeeks.org/merging-intervals/amp/
@sunidhihegde2422 жыл бұрын
Inside for loop if condition is static rt ?
@abhinavmishra76173 жыл бұрын
Very nicely explained. Thankyou
@ankitasingh6342 жыл бұрын
you are a life saver !!
@classcure97694 жыл бұрын
bro i have a nlog(n) binary search solution of this problem(only if given intervals are sorted)........ first make two diff arrays ---start and end where start[i] = Interval[i][0] and end[i] = Interval[i][1] then iterate over end array suppose we are at ith pos then using lower_bound function i can found position in start array which are less the E[i] suppose we get position a then add our first meged interval(which is start[i] , end[a]) into Ans(you can use vector) and then our new position for repeating the same process will be a+1...............................isn't it right aproach(for lower_bound i can also implement it in Log(n) time)................Hoping for a reply
@jatinkumar44103 жыл бұрын
understood....thanks for such nice explanation
@zishanchaudhary221 Жыл бұрын
Just Amazing 🥳🥳
@arvindmaurya71574 жыл бұрын
Really helpful for everyone...
@ESaiCharanKNetha3 жыл бұрын
This video is helpful, thanks.
@akanshakedia99332 жыл бұрын
Can you explain how arrays.sort(intervals,(a,b)->a[0],b[0]) works?
@rahul_ji212 жыл бұрын
did u get it??
@soumyabanerjee38862 жыл бұрын
this is a lambda expression
@vasugaur12833 жыл бұрын
bro thankyou for making such videos....plz post more videos
@rajeshagarwal41372 жыл бұрын
This question is famous fir JPMC coding round
@harshitkumarsingh23493 жыл бұрын
if your submission on leetcode for this code is only better then 38% coders then try to return intervals if it's size is equal to 1 or 0 you will be better then 99%.
@takeUforward3 жыл бұрын
Leetcode runtimes are myth lol
@100kb32 жыл бұрын
currently doing Graphs Series ( new ) Next tree's series, Awesome explanation!
@apoorvsingh62723 жыл бұрын
Great explanation bro
@tejassrivastava69713 жыл бұрын
Thanks for this playlist
@EdwinaNeheru694 жыл бұрын
Thank u bhai...grt work keep going...👌👌👌
@anuragroshan21952 жыл бұрын
THOSE WHO ARE LOOKING FOR SOLUTION WITHOUT USING SORT FUNCTION Here i used a map and TC of code is O(2n) public: vector merge(vector& intervals) { int arr[10000+5]; mapmp; memset(arr,-1,sizeof(arr)); int count=-1; int n=intervals.size(); for(int i=0; imp[intervals[i][0]]){ mp[intervals[i][0]]=intervals[i][1]; } arr[intervals[i][0]]=1; arr[intervals[i][1]]=1; } int num=0; for(int i=0 ; i
@ECEGrishmaKarekar2 жыл бұрын
wow thats a good solution
@acxd4 жыл бұрын
Understood great explaination!
@mukulmishra244 жыл бұрын
Bro this thumbnail 🤩🤩
@thisisjustme81493 жыл бұрын
Very well understood, thanks a lot!!
@gopinath78464 жыл бұрын
please explain what is time complex and space complex it will be good to understand as well
@nehasagar94164 жыл бұрын
Was waiting for the video
@936_pratikgupta43 жыл бұрын
The code is easy to understand but you will get 2 testcase error due to the first if condition in which the if(intervals.length==0 || intervals.length==null) change it to if(intervals.lenght
@namanbhardwaj36214 жыл бұрын
bhaiya I understood th problem. I liked the old video thumbnail. thanks and keep doing
@sathyapriyaar10093 жыл бұрын
great work!!
@GrimReaper-gt2xs2 жыл бұрын
Thank you so much❤️
@saimahaider17833 жыл бұрын
it was really helpful
@JamWithJingle3 жыл бұрын
Thanks
@roushanraj85304 жыл бұрын
Big big Thank you bro.......
@jigyasakodnani38724 жыл бұрын
Thanks alot for the video!!
@DeadPoolx1712Ай бұрын
UNDERSTOOD;
@satyamsingh_474 жыл бұрын
Please help me with the last line of your java code. why can't we simply write return res.toArray() instead of return res.toArray(new int[0][]) ?
@sksahil14614 жыл бұрын
Thank you striver
@aravindbalaji15034 жыл бұрын
Can we change the first condition to intervals.size()