Merge Overlapping Intervals | Brute, Optimal with Precise TC analysis

  Рет қаралды 197,017

take U forward

take U forward

Күн бұрын

Пікірлер: 265
@takeUforward
@takeUforward Жыл бұрын
Please watch our new video on the same topic: kzbin.info/www/bejne/f5bbf2lmoJtloNE
@sarthakchavhan
@sarthakchavhan 5 ай бұрын
ye kya recurrsion chala rahe ho bhaiya 👀
@asutoshpanda2426
@asutoshpanda2426 4 ай бұрын
it could be more space optimized if u traverse it in the same place rather than creating ans to store each of them .......i passed all testcases in this approach
@takeUforward
@takeUforward Жыл бұрын
Do give us a like if you understood everything, it won't cost you much :)
@mohdalizilani9896
@mohdalizilani9896 Жыл бұрын
Hey Bro! 🎉 Your Graph and DP series is absolutely fantastic! 👌 Your content is top-notch and stands out from the rest. I've been searching everywhere, and your quality is unmatched. 😍 I do have a humble request - could you consider creating a compact playlist on Digit DP? Lately, I've encountered several LeetCode contests with questions related to Digit DP, and I'm struggling to crack them. I'm sure many of us are in the same boat. 💡 If you're on board with the idea of adding videos on DIGIT DP, please show your support by giving this comment a thumbs up! 👍 Let's learn and grow together. 📚💪
@Akash-yr2if
@Akash-yr2if Жыл бұрын
This is the first question where I took 1hr to understand the Brute force & 10 min to understand the Optimal logic 🙂
@tot7997
@tot7997 Жыл бұрын
22 min ka to vvideo he lodu
@Akash-yr2if
@Akash-yr2if Жыл бұрын
@@tot7997 Comment parke samajna ka dimak bhi chahihe chomu
@tot7997
@tot7997 Жыл бұрын
@@Akash-yr2if thoda humor bhi chahiye ig
@TathagatTiwari-t6b
@TathagatTiwari-t6b Жыл бұрын
coz both are the same... I mean he just decreases the complexity from O(2*n) to O(n) and for Java it didn't even do that bcoz we have to convert a list to an array at the end, So it remains O(2*n)
@nuclearbaba1769
@nuclearbaba1769 Жыл бұрын
no problem bro we are playing with logic we don't take seriously to converting languages complexity @@TathagatTiwari-t6b
@darshanrokkad5216
@darshanrokkad5216 9 ай бұрын
understanding of brute force took me more time than understanding of optimal
@OrderEmperor
@OrderEmperor 7 ай бұрын
To make his video in his regular pattern he intentionally adds unnecessary solutions and calls them brute force..
@anandpandey918
@anandpandey918 4 ай бұрын
/* Given two intervals, [a, b] and [c, d], the condition for these intervals to overlap can be expressed as: a = c This condition checks if the end of the first interval (b) is not before the start of the second interval (c), and the start of the first interval (a) is not after the end of the second interval (d). If both these conditions are true, the intervals overlap. Ex : [1, 3],[2, 6] => [1, 6] [2, 9],[1, 6] => [1, 9] [1, 3], [3, 3]=> [1, 3] [1,8], [2, 3] =>[1, 8] [2, 4], [1, 8]=>[1, 8] why just not b>=c ,what is the need of a= c, these intervals would overlap because 3(b) is greater than 1 (c). However, when you look at the intervals on a timeline, you see that [8, 3] starts after [1, 6] has already ended. So, they don't actually overlap. That's why we also need the condition a
@shravanpai8947
@shravanpai8947 3 ай бұрын
Hard work pays off brother. Here is the reason for being the first person to get placed in the batch. All the very best from your junior😇
@JEE-nf1cv
@JEE-nf1cv 3 ай бұрын
@@OrderEmperor Learning from him and spreading toxicity
@OrderEmperor
@OrderEmperor 3 ай бұрын
@@JEE-nf1cv ok bro 😂😂 still I am not wrong if you actually watch his videos
@NithinvKumar-uk2he
@NithinvKumar-uk2he Жыл бұрын
One of the greatest free course that I ever seen in KZbin
@badass_yt7962
@badass_yt7962 Жыл бұрын
I generally do not comment even on good videos, but after watching this video, i really wanna say amazing explanation. You made a difficult problem easy. Excellent clarity of concept. Striver, you are the best💯
@shubhamagarwal1434
@shubhamagarwal1434 3 ай бұрын
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India..
@syedFAHIM-el1wr
@syedFAHIM-el1wr Жыл бұрын
By Liking , We also tell you tube algorithm that provide us with such content instead of distracting useless videos!!! When i understood this, I started liking every quality content videos and my recommendation is now really good. Understood! I was able to build up the logic but could not code it by myself... Waiting for that magic to happen when i can code even listening to music
@Shubham-et8qk
@Shubham-et8qk Ай бұрын
Meanwhile me who remove recommendations 🗿
@sasanklakimsetti8967
@sasanklakimsetti8967 Ай бұрын
Understood very well. Thought that the problem would be extremely tough by looking at the question. But he proved me wrong with his explanation.
@iWontFakeIt
@iWontFakeIt Жыл бұрын
I think my code is more intuitive (atleast to me) rather than the code you shown.(both approaches are same) (also I am not complaining, I am sharing this so that others can also share their opinion on mine). Below is my code: #include /* intervals[i][0] = start point of i'th interval intervals[i][1] = finish point of i'th interval */ vector mergeIntervals(vector &intervals) { int n = intervals.size(); sort(begin(intervals), end(intervals)); vector ans; int i = 1; int start = intervals[0][0], end = intervals[0][1]; while(i
@jayrathod7957
@jayrathod7957 11 ай бұрын
bro........ i just write same code but little different........... vector ans; int n=arr.size(); int lastf=-1,lasts=-1; for(int i=0;i=first) { lastf=min(lastf,first); lasts=max(lasts,second); } else{ vector temp; temp.push_back(lastf); temp.push_back(lasts); ans.push_back(temp); lastf=first; lasts=second; } } else{ lastf=first; lasts=second; } } vector temp; temp.push_back(lastf); temp.push_back(lasts); ans.push_back(temp); return ans;
@anshikavlogs8269
@anshikavlogs8269 Жыл бұрын
you make this question so easy to be understood by your proper explanation .🔥🔥 really thanks a lot
@rishabh1S
@rishabh1S Жыл бұрын
Two videos in a day ✅
@deathigniter2155
@deathigniter2155 5 ай бұрын
i am glad i was able to think of optimal solution directly and didnt even realised it was optimal. Felt like Brute Force was more tougher than the optimal one. LOL
@sayamparejiya1510
@sayamparejiya1510 5 ай бұрын
nice bro but how? through practice ?
@deathigniter2155
@deathigniter2155 5 ай бұрын
@@sayamparejiya1510 yes brother... i have solved like 700 problems on CF and 400 + on GFG and Codechef combined.... so it takes alot of practice. but yeah number of questions doesnt matter... Good questions matter which teach you something that you can carry to 10 next questions
@sayamparejiya1510
@sayamparejiya1510 5 ай бұрын
@@deathigniter2155 Thank for sharing.
@vivekdongare2289
@vivekdongare2289 2 ай бұрын
Lol same for me xD
@wanderer_ankur
@wanderer_ankur 10 ай бұрын
Man i have always been scared of arrays especially but after going through this sheet gradually my confidence is increasing. This is such a good resource for learning DSA. Thanks a lot striver bro for making this :)
@jatinukey4062
@jatinukey4062 5 ай бұрын
The approaches you have taught in this video, 60-70% both the approaches come in my mind but i was struggling to implement it. Thank you very much bhaiya for this video! You are always a great tutor for me and everyone ❤❤
@mehulthuletiya497
@mehulthuletiya497 Жыл бұрын
00:41 Problem Statement 01:15 Overlapping example 03:27 Brute force 03:56 approach 09:39 Code 13:30 Complexity 16:22 Optimal approach 16:38 Intuition 18:55 Code 21:36 Complexity
@AyushKumar-ju9jj
@AyushKumar-ju9jj Жыл бұрын
This man deserves a salute!
@Braveuser-x7j
@Braveuser-x7j Жыл бұрын
when I see your video i thought why we don't get this type of teacher in our engineering college .... i think 1.5 st years is enough to crack any coding interview .....💖💖💖💖💖💖❤❤❤❤❤❤❤❤
@Astro-Coder
@Astro-Coder Ай бұрын
you are such an incredible teacher
@Rama-si9sp
@Rama-si9sp Ай бұрын
Sir you are god gifted teacher for us
@aryanthapa5540
@aryanthapa5540 10 ай бұрын
was watching this tutorial on your website before after watching the video I came here to just like and comment on this video to tell how beautiful the explanation was loved it striver bhaiya❤❤
@notcountdankula
@notcountdankula Жыл бұрын
Python Code 🐍 class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: ans = [] intervals.sort() ans.append(intervals[0]) for i in intervals: start = i[0] end = i[1] if start
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you so so much for your effort!!
@qjawed9654
@qjawed9654 7 ай бұрын
I usually don't write comment but I think this time I should. Amazing explanation Sir. Thank You
@alphaCont
@alphaCont 11 ай бұрын
we can do it O(1) also in space, by checking the next element if it is overlapped we just change the current elements [1] element with max, than we just remove the [i+1] from the array and in the end we will have just our answer
@artifice_abhi
@artifice_abhi 11 ай бұрын
A little change in the code (although striver's code is shorter) by updating the end every time we move to the next index: vector overlappedInterval(vector& intervals) { // Code here sort(intervals.begin() , intervals.end()); vector ans; int start = intervals[0][0]; int end = intervals[0][1]; for(int i = 1; i
@mr.kinjalchoudhary.7982
@mr.kinjalchoudhary.7982 4 ай бұрын
while i was staring at the question i did my self come up with the optimal solution.
@urvashi2410
@urvashi2410 Жыл бұрын
It was so easy code at the end!! Thanks Striver.
@ritikrajsinha5895
@ritikrajsinha5895 Жыл бұрын
bhaiya u re inspiration to all thrown ones like us thank u get a lot hope from u
@SAURABHKUMAR-yo7er
@SAURABHKUMAR-yo7er 5 ай бұрын
i was able to do the optimal solution on my own , feeling good 😌
@crix_05
@crix_05 9 ай бұрын
18:33 "I am inside you" - Striver
@swetaacharya2969
@swetaacharya2969 Жыл бұрын
Thank you sir for providing such great content ❤
@priyankavasam8769
@priyankavasam8769 Жыл бұрын
Couldn't thank you enough sir!! You are the savior
@eklavya22k34
@eklavya22k34 5 ай бұрын
Understood, amazing coding , love it.
@Corvo1837
@Corvo1837 10 күн бұрын
Great explanation, understood!
@rohitchanda8461
@rohitchanda8461 10 ай бұрын
So beautifully explained.
@rahuljain224
@rahuljain224 8 ай бұрын
Excellent explanation Thank you so much 🎉 sir
@studynewthings1727
@studynewthings1727 Жыл бұрын
Thnk you, its helpful for me! to understand this concept very well.
@sarangkumarsingh7901
@sarangkumarsingh7901 8 ай бұрын
Understood Sir...........Enjoyed this lec...........
@YashRaj-jt1ee
@YashRaj-jt1ee Ай бұрын
Superb explanation sir
@selvaarumugam370
@selvaarumugam370 Жыл бұрын
as usuall u jus made the problem loook easy bruh!!!!
@venkatsaireddy1412
@venkatsaireddy1412 9 ай бұрын
Understood Bro Thank You for Upskilling us.
@viditvaish7317
@viditvaish7317 Жыл бұрын
amazing explanation always worth watching your videos
@Manishgupta200
@Manishgupta200 Жыл бұрын
That's really easy to understable. Thankyou
@AshishBharti-xr5by
@AshishBharti-xr5by Жыл бұрын
i just want to say ,thank you thank you very much ..❤
@deepanshudahiya8966
@deepanshudahiya8966 5 ай бұрын
Understood and I even made the algorithm myself before watching solution but wasnt able to write the code
@bandlashashankreddy
@bandlashashankreddy Жыл бұрын
Thank you for your wonderful explanation. Understood🙂
@3rd_Eye_Gang
@3rd_Eye_Gang Жыл бұрын
🤩🤩 Thank you Raj Bhaiya...
@isheep9025
@isheep9025 Жыл бұрын
simple implementation of optimal method: #include #include vector mergeOverlappingIntervals(vector &arr) { sort(arr.begin(),arr.end()); vector ans; vector tmp={arr[0][0],arr[0][1]}; for(auto p:arr) { if(tmp[1]>=p[0]) { tmp[1]=max(tmp[1],p[1]); continue; } ans.push_back(tmp); tmp={p[0],p[1]}; } ans.push_back(tmp); return ans; }
@AmanPandey-bd1sj
@AmanPandey-bd1sj Жыл бұрын
Best Explanation bhaiya thanks a lot 🙏
@Infinull-w8d
@Infinull-w8d 7 ай бұрын
So Instead of making a new int[][] ans. We can use the same given array to store answer. Which can potentially reduce the usage of extra space for storing answer.
@rickk3300
@rickk3300 Жыл бұрын
Striver ke itne saare DSA ke videos dekh liye, ab soch kar hi ajeeb lagta hai ki bhaiya kisi zamane me CP karte the....😅
@AniketKumar-hf2bo
@AniketKumar-hf2bo 9 ай бұрын
understood ,thnx for the amazing expplanation ❤❤❤❤👌👌
@chandansolanki2566
@chandansolanki2566 6 ай бұрын
thank you sir , very nicely explained😊
@bhargavijethva7958
@bhargavijethva7958 8 ай бұрын
Very nice explanation!👏👏
@codershour
@codershour Жыл бұрын
I'm still hustling, but this feeling is good
@souvikbasak7720
@souvikbasak7720 8 ай бұрын
There is an edge case, if ans.back()[0] > arr[I][0] you can put ans.back()[0] = min(ans.back()[0],arr[i][0]); in else part
@30_mithleshyadav65
@30_mithleshyadav65 2 ай бұрын
This case will never arise as we have already sorted the arr in the starting. So the condition ans.back()[0]>ans[i][0] will never arise
@mokshjain4985
@mokshjain4985 Ай бұрын
Great Work👍👍
@abhaypatel379
@abhaypatel379 5 ай бұрын
Thankyou @TUF 😮
@rishikeshkmr
@rishikeshkmr 26 күн бұрын
Understood. Thanks!
@grishmitaagrawal8496
@grishmitaagrawal8496 Ай бұрын
UNDERSTOOD !!
@pasej5
@pasej5 9 ай бұрын
Thank you bro this is good teaching
@Adarsh_agrahari
@Adarsh_agrahari 10 ай бұрын
What a ques but apart from this what a explenation😊
@Soumyadeepd21
@Soumyadeepd21 5 ай бұрын
brute force seems to be more complex than the optimize one :)....btw superb content
@rajveersingh2056
@rajveersingh2056 Жыл бұрын
Lots of elements said: ham alag hai... Hamko apne se na jodiye.
@shivamehta6537
@shivamehta6537 Жыл бұрын
Just want to ask how to remember so many optimal approaches and what to do if a question comes in an interview which I have never seen before?
@takeUforward
@takeUforward Жыл бұрын
Comes with practice, you will get used to it.
@Vardanaggarwal
@Vardanaggarwal 9 ай бұрын
awesome explanation bhaiya
@GhostVaibhav
@GhostVaibhav Жыл бұрын
Understood🔥
@ShahNawaz-t7p7k
@ShahNawaz-t7p7k 4 ай бұрын
After reading the question I optimally solved by myself, I thought that this is the only way to solve and it is also marked as easy on leetcode but when I watched the brute solution, it gave me the vibe that we are forcefully creating the brute-force solution for this problem, so I don't think that it is necessary to explain brute force solution of such problems to the interviewer. What are your thoughts on this guys?
@BG-lj6fw
@BG-lj6fw Жыл бұрын
understood!. great as always. btw @striver the brute force code on the website is same for cpp and js (js code has been given in cpp as well ) kindly correct it.
@utsavseth6573
@utsavseth6573 Жыл бұрын
Great work raj.
@NazeerBashaShaik
@NazeerBashaShaik 8 ай бұрын
Understood, thank you.
@aniketkashid8289
@aniketkashid8289 Жыл бұрын
Great Explanation Sir
@DeadPoolx1712
@DeadPoolx1712 3 ай бұрын
UNDERSTOOD:
@CodewithKing360
@CodewithKing360 5 ай бұрын
optimal solution is optimal to understanding than brutforce😁
@culeforever5408
@culeforever5408 Жыл бұрын
understood 🤠
@divyanjalimourya1669
@divyanjalimourya1669 Жыл бұрын
Nice explanation
@harshilpatel3205
@harshilpatel3205 3 ай бұрын
Understood 🙏🏻
@shashankgsharma0901
@shashankgsharma0901 4 ай бұрын
Understood! but took lot of time.
@yaxlu
@yaxlu Жыл бұрын
Thank you! Understood!
@matbarjoshi7891
@matbarjoshi7891 Жыл бұрын
Inspiration 🙏🏽🙏🏽
@YourCodeVerse
@YourCodeVerse Жыл бұрын
Understood✅🔥🔥
@Lucifer-xt7un
@Lucifer-xt7un Жыл бұрын
Please maintain consistency brother
@DeepakPatel-d5v
@DeepakPatel-d5v 7 ай бұрын
Thanks a lot Bhaiya
@navneetrai9512
@navneetrai9512 4 ай бұрын
bhai ne jayese hi bola sort krrlo , then it took just 5 min🤣🤣
@habeeblaimusa4466
@habeeblaimusa4466 Жыл бұрын
Bro, is it normal to come up with optimal solution intuition without bruteforce because, sometimes whenever a question comes up the first solution that sometimes comes up is optimal. It is sometimes hard for me to come up with bruteforce
@takeUforward
@takeUforward Жыл бұрын
It is okay, but if you know solutions before hand, and you don't want to tell to the interviewer, drive the interview..
@her_soulmate
@her_soulmate Жыл бұрын
Understood 🎉
@Monotonic_Stack
@Monotonic_Stack Жыл бұрын
god of dsa
@RiyaSharma-k9p
@RiyaSharma-k9p 10 ай бұрын
Understood striver😇
@pulkitgupta669
@pulkitgupta669 Жыл бұрын
Understood ❤❤
@nitinchandrasahu1774
@nitinchandrasahu1774 8 ай бұрын
Thank You😄
@AbhishekBhattacharjee-j2m
@AbhishekBhattacharjee-j2m Жыл бұрын
UNDERSTOOD
@aniketbhura6131
@aniketbhura6131 5 ай бұрын
much simpler class Solution { public: vector merge(vector& nums) { vectorans; sort(nums.begin() , nums.end()); ans.push_back({nums[0][0] , nums[0][1]}); for(int i=1;i
@suyashrahatekar4964
@suyashrahatekar4964 Жыл бұрын
I thought of the same brute force approach (with O(nlogn) time) after much thought but I didnt know u can sort 2d vector like that.
@dishankbaid9809
@dishankbaid9809 Жыл бұрын
Amazing!
@santoshrawat3605
@santoshrawat3605 4 ай бұрын
i there is mistake in brute force check condition istead of end
@shobhitsrivastava1223
@shobhitsrivastava1223 Жыл бұрын
Understood❤
@MohitKumar-o3l1u
@MohitKumar-o3l1u 8 ай бұрын
Understood.
@abhinay.k
@abhinay.k Ай бұрын
thanks
@yasinsherif8875
@yasinsherif8875 Ай бұрын
bro thankyou verymuch
Merge Sorted Arrays Without Extra Space | 2 Optimal Solution
32:47
take U forward
Рет қаралды 217 М.
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 138 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Number of Subarrays with xor K | Brute - Better - Optimal
24:55
take U forward
Рет қаралды 146 М.
Transformers (how LLMs work) explained visually | DL5
27:14
3Blue1Brown
Рет қаралды 3,8 МЛН
Maximum Product Subarray - Best Intuitive Approach Discussed
20:27
take U forward
Рет қаралды 236 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 150 М.
I solved 541 Leetcode problems. But you need only 150.
7:42
Sahil & Sarra
Рет қаралды 2,4 МЛН
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 442 М.
Count Inversions in an Array | Brute and Optimal
24:17
take U forward
Рет қаралды 242 М.