Merge Overlapping Intervals | Brute, Optimal with Precise TC analysis

  Рет қаралды 167,103

take U forward

take U forward

Күн бұрын

Пікірлер: 232
@takeUforward
@takeUforward Жыл бұрын
Please watch our new video on the same topic: kzbin.info/www/bejne/f5bbf2lmoJtloNE
@sarthakchavhan
@sarthakchavhan 2 ай бұрын
ye kya recurrsion chala rahe ho bhaiya 👀
@asutoshpanda2426
@asutoshpanda2426 Ай бұрын
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
@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
@user-je7tz6le4k
@user-je7tz6le4k Жыл бұрын
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 @@user-je7tz6le4k
@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. 📚💪
@darshanrokkad5216
@darshanrokkad5216 6 ай бұрын
understanding of brute force took me more time than understanding of optimal
@OrderEmperor
@OrderEmperor 4 ай бұрын
To make his video in his regular pattern he intentionally adds unnecessary solutions and calls them brute force..
@anandpandey918
@anandpandey918 Ай бұрын
/* 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 Ай бұрын
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 25 күн бұрын
@@OrderEmperor Learning from him and spreading toxicity
@OrderEmperor
@OrderEmperor 25 күн бұрын
@@JEE-nf1cv ok bro 😂😂 still I am not wrong if you actually watch his videos
@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💯
@NithinvKumar-uk2he
@NithinvKumar-uk2he Жыл бұрын
One of the greatest free course that I ever seen in KZbin
@deathigniter2155
@deathigniter2155 3 ай бұрын
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 2 ай бұрын
nice bro but how? through practice ?
@deathigniter2155
@deathigniter2155 2 ай бұрын
@@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 2 ай бұрын
@@deathigniter2155 Thank for sharing.
@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 8 ай бұрын
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;
@rishabh1S
@rishabh1S Жыл бұрын
Two videos in a day ✅
@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
@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
@anshikavlogs8269
@anshikavlogs8269 Жыл бұрын
you make this question so easy to be understood by your proper explanation .🔥🔥 really thanks a lot
@wanderer_ankur
@wanderer_ankur 7 ай бұрын
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 :)
@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
@crix_05
@crix_05 7 ай бұрын
18:33 "I am inside you" - Striver
@jatinukey4062
@jatinukey4062 3 ай бұрын
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 ❤❤
@artifice_abhi
@artifice_abhi 8 ай бұрын
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
@alphaCont
@alphaCont 8 ай бұрын
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
@shubhamagarwal1434
@shubhamagarwal1434 Ай бұрын
#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..
@AyushKumar-ju9jj
@AyushKumar-ju9jj Жыл бұрын
This man deserves a salute!
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you so so much for your effort!!
@qjawed9654
@qjawed9654 4 ай бұрын
I usually don't write comment but I think this time I should. Amazing explanation Sir. Thank You
@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.
@user-sp8ne7hj3n
@user-sp8ne7hj3n Жыл бұрын
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 .....💖💖💖💖💖💖❤❤❤❤❤❤❤❤
@user-pq9hi1wr5z
@user-pq9hi1wr5z 4 ай бұрын
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.
@aryanthapa5540
@aryanthapa5540 7 ай бұрын
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❤❤
@mr.kinjalchoudhary.7982
@mr.kinjalchoudhary.7982 Ай бұрын
while i was staring at the question i did my self come up with the optimal solution.
@deepanshudahiya8966
@deepanshudahiya8966 3 ай бұрын
Understood and I even made the algorithm myself before watching solution but wasnt able to write the code
@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
@souvikbasak7720
@souvikbasak7720 6 ай бұрын
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
@SAURABHKUMAR-yo7er
@SAURABHKUMAR-yo7er 2 ай бұрын
i was able to do the optimal solution on my own , feeling good 😌
@eklavya22k34
@eklavya22k34 3 ай бұрын
Understood, amazing coding , love it.
@swetaacharya2969
@swetaacharya2969 Жыл бұрын
Thank you sir for providing such great content ❤
@priyankavasam8769
@priyankavasam8769 Жыл бұрын
Couldn't thank you enough sir!! You are the savior
@sarangkumarsingh7901
@sarangkumarsingh7901 5 ай бұрын
Understood Sir...........Enjoyed this lec...........
@culeforever5408
@culeforever5408 10 ай бұрын
understood 🤠
@rahuljain224
@rahuljain224 5 ай бұрын
Excellent explanation Thank you so much 🎉 sir
@rohitchanda8461
@rohitchanda8461 7 ай бұрын
So beautifully explained.
@studynewthings1727
@studynewthings1727 Жыл бұрын
Thnk you, its helpful for me! to understand this concept very well.
@viditvaish7317
@viditvaish7317 11 ай бұрын
amazing explanation always worth watching your videos
@AshishBharti-xr5by
@AshishBharti-xr5by Жыл бұрын
i just want to say ,thank you thank you very much ..❤
@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..
@selvaarumugam370
@selvaarumugam370 Жыл бұрын
as usuall u jus made the problem loook easy bruh!!!!
@venkatsaireddy1412
@venkatsaireddy1412 7 ай бұрын
Understood Bro Thank You for Upskilling us.
@Manishgupta200
@Manishgupta200 Жыл бұрын
That's really easy to understable. Thankyou
@bandlashashankreddy
@bandlashashankreddy Жыл бұрын
Thank you for your wonderful explanation. Understood🙂
@GhostVaibhav
@GhostVaibhav Жыл бұрын
Understood🔥
@chandansolanki2566
@chandansolanki2566 3 ай бұрын
thank you sir , very nicely explained😊
@AniketKumar-hf2bo
@AniketKumar-hf2bo 6 ай бұрын
understood ,thnx for the amazing expplanation ❤❤❤❤👌👌
@AmanPandey-bd1sj
@AmanPandey-bd1sj 10 ай бұрын
Best Explanation bhaiya thanks a lot 🙏
@DeadPoolx1712
@DeadPoolx1712 17 күн бұрын
UNDERSTOOD:
@harshilpatel3205
@harshilpatel3205 29 күн бұрын
Understood 🙏🏻
@bhargavijethva7958
@bhargavijethva7958 6 ай бұрын
Very nice explanation!👏👏
@NazeerBashaShaik
@NazeerBashaShaik 5 ай бұрын
Understood, thank you.
@pasej5
@pasej5 6 ай бұрын
Thank you bro this is good teaching
@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.
@kushagrakansal2705
@kushagrakansal2705 7 ай бұрын
what is meant by ans.back()? what does it do?
@abhaypatel379
@abhaypatel379 2 ай бұрын
Thankyou @TUF 😮
@sumitworld918
@sumitworld918 Ай бұрын
Understood ❤
@Soumyadeepd21
@Soumyadeepd21 2 ай бұрын
brute force seems to be more complex than the optimize one :)....btw superb content
@Adarsh_agrahari
@Adarsh_agrahari 7 ай бұрын
What a ques but apart from this what a explenation😊
@shashankgsharma0901
@shashankgsharma0901 2 ай бұрын
Understood! but took lot of time.
@Vardanaggarwal
@Vardanaggarwal 7 ай бұрын
awesome explanation bhaiya
@yaxlu
@yaxlu Жыл бұрын
Thank you! Understood!
@matbarjoshi7891
@matbarjoshi7891 Жыл бұрын
Inspiration 🙏🏽🙏🏽
@aniketkashid8289
@aniketkashid8289 11 ай бұрын
Great Explanation Sir
@3rd_Eye_Gang
@3rd_Eye_Gang Жыл бұрын
🤩🤩 Thank you Raj Bhaiya...
@user-qh3uf5gz5f
@user-qh3uf5gz5f Ай бұрын
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?
@kirtipalve1772
@kirtipalve1772 3 ай бұрын
Can one of the solutions be using a set? We mark all the numbers within intervals in a set ranging from smallest number to the largest number in the array. Then we iterate over the set and select the consecutive numbers as one interval?
@santoshrawat3605
@santoshrawat3605 Ай бұрын
i there is mistake in brute force check condition istead of end
@YourCodeVerse
@YourCodeVerse 10 ай бұрын
Understood✅🔥🔥
@utsavseth6573
@utsavseth6573 Жыл бұрын
Great work raj.
@maccode07
@maccode07 15 күн бұрын
Understood
@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; }
@kshitijkhowal6147
@kshitijkhowal6147 7 күн бұрын
understood
@her_soulmate
@her_soulmate 9 ай бұрын
Understood 🎉
@divyanjalimourya1669
@divyanjalimourya1669 Жыл бұрын
Nice explanation
@dishankbaid9809
@dishankbaid9809 Жыл бұрын
Amazing!
@codershour
@codershour Жыл бұрын
I'm still hustling, but this feeling is good
@nitinchandrasahu1774
@nitinchandrasahu1774 5 ай бұрын
Thank You😄
@pankajkumargajpalla2924
@pankajkumargajpalla2924 2 ай бұрын
u r awsome sir:)
@raaviumasusmitha937
@raaviumasusmitha937 14 күн бұрын
understood🥺
@brijeshsinghbhartiya3125
@brijeshsinghbhartiya3125 6 күн бұрын
great !!!!!!!!!
@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.
@RituSingh-ne1mk
@RituSingh-ne1mk 8 ай бұрын
Understood!
@AkashBisht-cq3ys
@AkashBisht-cq3ys 3 ай бұрын
2 June Sunday 9.4pm
@himanshukaushik9223
@himanshukaushik9223 Жыл бұрын
Start and end kaisa Lena ha samaj nahi aya arr[i][0] and arr[i][1] ??
@takeUforward
@takeUforward Жыл бұрын
list ka concept clear kar lo ek baar, ye video se pahle.
@himanshukaushik9223
@himanshukaushik9223 Жыл бұрын
​@@takeUforward samaj agaya row n col 2 hai o based indexing hai
@user-or5oz1pk2x
@user-or5oz1pk2x 4 ай бұрын
Thanks a lot Bhaiya
@user-nk1mb5fy7j
@user-nk1mb5fy7j Жыл бұрын
UNDERSTOOD
@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....😅
@user-uv5or5bm2c
@user-uv5or5bm2c 6 ай бұрын
Understood.
@AkGoyal-d7b
@AkGoyal-d7b Ай бұрын
the best
@soumiyamuthuraj3516
@soumiyamuthuraj3516 2 ай бұрын
Awesome
@CodewithKing360
@CodewithKing360 2 ай бұрын
optimal solution is optimal to understanding than brutforce😁
@sahilkholia2355
@sahilkholia2355 Жыл бұрын
true . great
@TheMadRunner00
@TheMadRunner00 Жыл бұрын
Brute force approach would be O(N^2) like you pick every element and loop over others on the right?
@nayankhuman1043
@nayankhuman1043 Ай бұрын
understood :)
@RahulKumar-zp1ln
@RahulKumar-zp1ln Жыл бұрын
Amazing
@yamini436
@yamini436 Жыл бұрын
love you striver :)
Merge Sorted Arrays Without Extra Space | 2 Optimal Solution
32:47
take U forward
Рет қаралды 184 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 486 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 91 МЛН
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 16 МЛН
How Top Teams are Winning by BREAKING This GOLDEN Rule
37:26
Number of Subarrays with xor K | Brute - Better - Optimal
24:55
take U forward
Рет қаралды 124 М.
The Last Algorithms Course You'll Need by ThePrimeagen | Preview
16:44
Frontend Masters
Рет қаралды 317 М.
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 840 М.
Merge intervals #Leetcode #Interviewbit C++
10:24
Code with Alisha
Рет қаралды 27 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 249 М.
3 Sum | Brute -  Better - Optimal with Codes
38:25
take U forward
Рет қаралды 299 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН