BS-21. Median of two Sorted Arrays of Different Sizes | Binary Search Approach With Intuition

  Рет қаралды 182,371

take U forward

take U forward

Күн бұрын

Пікірлер: 376
@ravirajshelar250
@ravirajshelar250 Жыл бұрын
The going into recursion for swapping idea was 🔥
@easylearn8924
@easylearn8924 11 ай бұрын
can you explain why he does that?? or we also use min(n1,n2) but it gives runtime error why??
@tovenkatesh82
@tovenkatesh82 10 ай бұрын
@@easylearn8924 the idea is to do a binary search over the smaller-size array. while loop is written based on that and that's why using min(n1,n2) would give you error.
@easylearn8924
@easylearn8924 10 ай бұрын
ok thanks@@tovenkatesh82
@ashish4k07
@ashish4k07 10 ай бұрын
@@easylearn8924 If we do that that's also possible but the code complexity will be too large and the std. while loop of binary search won't work even I understood after that video.
@easylearn8924
@easylearn8924 10 ай бұрын
why it won't work in while loop can you explain?? because i able to understand but after sometime i confused in this part??@@ashish4k07
@abhik6400
@abhik6400 6 ай бұрын
There is no way that you can come up with this optimal solution in an interview. Although the better solution using merge procedure from merge sort was pretty thinkable and doable but this is a completely genius solution !!!
@titusandronikus1337
@titusandronikus1337 5 ай бұрын
I came up with it on my own when solving it on Leetcode. Let’s be honest, the main idea is not very hard. But my problem was the actual implementation. You can see in the video just how many random +1 and -1 we need, as well as boundary checks. It’s crazy. I hoped Striver would find a way to make the code less ugly - sadly, no. The problem is just inherently very annoying
@abhik6400
@abhik6400 5 ай бұрын
@@titusandronikus1337 Really glad that you were able to come with the optimal solution on your own !!!!
@priyanshurana6027
@priyanshurana6027 4 ай бұрын
I came up with different approach on this one when solving on my own. It's similar to what we do in matrix's binary search I guess ( I have not watched striver's videos on it). Basically searching for kth element in any sorted arrays. It took O( log(m*n)*log(max-min)) time complexity, pretty big but it's in log and was accepted in leetcode.
@cosmicthor7330
@cosmicthor7330 4 ай бұрын
@@titusandronikus1337 same thought process is thinkable but seriously the implementation is though,hoestly i didnt understand fully
@rajat5040
@rajat5040 3 ай бұрын
@abhik6400 can u tell how it is doable from merge sort???
@sanketkumbhar8887
@sanketkumbhar8887 Жыл бұрын
He has already explained this in sde sheet but still he made a video for a2z sheet💯
@farazahmed7
@farazahmed7 Жыл бұрын
On which sheet has he explained this ? can you give me the link. Thanks
@mrlord8519
@mrlord8519 10 ай бұрын
​@@farazahmed7maybe from his sde sheet for placements
@omkarshendge5438
@omkarshendge5438 3 ай бұрын
@@farazahmed7 i think he is talking about the placement series or the sde sheet of 180 questions he made long time ago, you should check that out.
@yatendraupadhyay2180
@yatendraupadhyay2180 5 ай бұрын
Striver you are a real social reformer. At times when colleges are rendering students unemployable , you are making us industry ready. Dude Hats off to you.
@Dontpushyour_luck
@Dontpushyour_luck 11 ай бұрын
best video of entire playlist. I never understood this problem's binary search approach earlier, but you solved it so well. And that idea to call that function again if sizeof(b)
@VivekKumar-p2g4l
@VivekKumar-p2g4l 4 ай бұрын
Why we need to do that ? Can you explain
@Beeplov2337568
@Beeplov2337568 3 ай бұрын
@@VivekKumar-p2g4lIt might possible that the first array has greater size,so in order to take the shorter array to proceed he did it, hence TC : O(log(min(n1,n2)))
@ruturajchandgude6083
@ruturajchandgude6083 Жыл бұрын
Watched both videos twice ,all 3 approaches are crystal clear now,thank you!
@shubhambagul3127
@shubhambagul3127 Жыл бұрын
Waiting for this one for a long time no one explained this problem this well , Thank you.
@harshit.53
@harshit.53 5 ай бұрын
If i hadn't checked this video there is no way i would be able to think of this solution in interview Thanks...
@mrsmurf911
@mrsmurf911 11 ай бұрын
That swapping of the inputs and >>1 steps are 🔥 🔥
@ashish4k07
@ashish4k07 10 ай бұрын
bit manupulation and swapping is to low so yeah it improves time mostly
@harshhwardhanrai3716
@harshhwardhanrai3716 3 ай бұрын
This is the first video that I have not understood of you. No matter how many times I watch I just can't understand. I'm just skipping this optimal approach for now. :)
@TusharKumar-u4p
@TusharKumar-u4p 8 ай бұрын
I am so dumb even after solving good number of questions on leetcode I even could not even think of like this.
@ShubhamKumar-l2u2x
@ShubhamKumar-l2u2x 2 ай бұрын
same same
@arpitgoyal2035
@arpitgoyal2035 2 ай бұрын
you just have to understand all the concept better and try to practice more problems on your own and like solve some old problems as well to strength your concepts and get motivation.
@dp622
@dp622 Ай бұрын
these problems are standard problems aka basic ones, no one can come up with solutions of such problems unless they are god gifted in mathematics The problems in contest are variation of such basic problem which can be solved by all if they know basic problems.
@Vishal-s2g7c
@Vishal-s2g7c Ай бұрын
bro you get better by uderstand
@prajaktachachad477
@prajaktachachad477 7 ай бұрын
I wanna know, how you built your logic and how you became an expert in understanding this logic so well. I have been following your playlist for a couple of months and understood each problem so well. What steps do you follow in your initial stage to reach this point? Please help so that your valuable tips can help me crack coding interviews. Trust me you are simply Amazing and Genius :)
@SwatiSingh-ys6hm
@SwatiSingh-ys6hm Жыл бұрын
This is one of the bestest explanations I have come across. Totally cleared my concept. Thanks a lot sir !
@avinashkumar3116
@avinashkumar3116 Ай бұрын
If striver explains this question to a dead body and later asks him whether you understood or not. That dead body will yell from it's grave - "Understood Sir 💀☠"
@successfoundation8872
@successfoundation8872 25 күн бұрын
Woah bro that's deep😅
@utsavseth6573
@utsavseth6573 Жыл бұрын
Understood. GOod video striver. It's important to watch these important questions because it is not possible to invent these kind of solutions then and there itself.
@Dipanshutripathi2407
@Dipanshutripathi2407 Жыл бұрын
After watching so many videos i actually the found the gem which resolved my all the doubts in such a nice and simple way.
@Anshydv3
@Anshydv3 Жыл бұрын
The king of coding community 👑
@shikhirkalia6828
@shikhirkalia6828 10 ай бұрын
Best video explanation of this problem on the whole internet.
@stith_pragya
@stith_pragya 7 ай бұрын
UNDERSTOOD..........Thank You So Much for this wonderful video................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@ashwingoel7173
@ashwingoel7173 7 ай бұрын
At 17:57 shouldn't it be l1 > r2?
@rushidesai2836
@rushidesai2836 4 ай бұрын
Same thing i was thinkking
@aruna5869
@aruna5869 3 ай бұрын
I shocked at the end of video after seeing the way you explained this complex optimal solution!!!! Thanks a lot!❤‍🔥💥❤💯
@ArpanChakraborty-do6yz
@ArpanChakraborty-do6yz 7 ай бұрын
before watching this intution , my favourite intution was dutch national flag algo,,, but this question along with its explanation was beyond my imagination,,,, hats off to you.......and your expression after completing this ques shows how passionate you are about your work and this gives us too much motivation,,,thank you😇😇
@arjunc1482
@arjunc1482 7 ай бұрын
bro..how will you use dutch national flag algo for this question?
@ArpanChakraborty-do6yz
@ArpanChakraborty-do6yz 7 ай бұрын
@@arjunc1482 I am not saying I will use duch algo here,,, I have just stated among all algo/intuitions duch algo and it's question was my fav,,, but after watching this question and it's soln , it is my fav now
@Health_asset
@Health_asset 3 ай бұрын
Thanks striver to explain this . I was thinking that this is too much difficult concept but after watching this video , I can do the similar stuff myself. Thank you so much
@apmotivationakashparmar722
@apmotivationakashparmar722 Ай бұрын
Understood completely . Great man , you are God in DSA.
@JeffreyConcerto
@JeffreyConcerto Жыл бұрын
Such a thorough explanation! Exactly what I needed to help me understand this problem. Great energy throughout and the lesson was clearly well prepared and organized to educate and enlighten. Thank you!
@ArnabBhadra02
@ArnabBhadra02 Жыл бұрын
1 morning i would woke up and see striver had completed a2z series and i got my dream company.
@sahilbani7020
@sahilbani7020 Жыл бұрын
brilliant explanation, this problem is not only hard to do but also hard to explain
@abhicasm9237
@abhicasm9237 Жыл бұрын
I did it using the approach of two sorted lists question and got 2ms solution. But this is better
@rahulseetharaman4525
@rahulseetharaman4525 Жыл бұрын
Crystal clear explanation. Explained your heart out. Thank you :)
@BhaweshKumawat
@BhaweshKumawat 8 ай бұрын
17:55 l1 > r2
@linhnguyenduc641
@linhnguyenduc641 6 ай бұрын
You deeply understand the problem and explain the solution well. Thanks.
@ArunsinghParihar-j3j
@ArunsinghParihar-j3j Ай бұрын
Mind Blowing Solution approach
@dhananjayadhari6481
@dhananjayadhari6481 7 ай бұрын
Really wonderful approach and explanation
@t3ch_r4id
@t3ch_r4id Ай бұрын
Thanku for making optimal vedio separately for this problem 🥲❣️🙌🏻
@mano_003
@mano_003 Жыл бұрын
Thank u for doing things for us even in ur busy days...❤
@Sports590
@Sports590 Жыл бұрын
"Busy" are those People who disrespect others, People who respect are not Busy ❤
@Josuke217
@Josuke217 2 ай бұрын
This is a great approach, no way I could come up with this in an interview...
@yasaswinikarumuri9590
@yasaswinikarumuri9590 3 ай бұрын
I still can't imagine how would someone think of such an optimal solution? It's out of mind. Are we expected to think of such optimal soln? I'm asking this bcz, it took me lot of time to understand this soln even after a great explanation... Thank you striver for such a wonderful explanation !
@sibashis_12
@sibashis_12 11 ай бұрын
brilliant explanation. even hard topics seem easy when you explain them.
@bgovindnaren7405
@bgovindnaren7405 7 күн бұрын
thanks bro kya gajab video tha... smaj aa gaya...
@technicalworld6470
@technicalworld6470 Жыл бұрын
What a energy ! Thank you striver for amazing content 🙇
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always thank you very very much for your effort!!
@pranavindore2410
@pranavindore2410 11 ай бұрын
TOP notch explanation striver. I saw both videos. Understood completerly. Thank you.
@sumitkamble_
@sumitkamble_ Жыл бұрын
At first the brain wasn't braining but got it at the end great explanation
@sagark4080
@sagark4080 11 ай бұрын
@takeUforward, @30.01 generally in Binary search of array we consider left =0 and right=array.size()-1 correct? But here why have you considered low =0 and high=n1 ( which is array size itself) not n1-1?
@takeUforward
@takeUforward 11 ай бұрын
Yes because it means how many elements we take, either we can take 0 elements or we can take all which is n1
@Donquixote-Rosinante
@Donquixote-Rosinante 9 ай бұрын
i tried to do it in zero-based. if e.g nums1=[1,3] nums2 = [2]. arr1Left = 2, arr1Right = inf, arr2Left = -inf, arr2Right = 1. arr1Left
@amitranjan6998
@amitranjan6998 Жыл бұрын
Amazing, how you observe so minutely :) Bhai Hat's Off .
@dxvya23
@dxvya23 Жыл бұрын
Once again, your explanation is top-notch.
@playwithlinux
@playwithlinux 3 ай бұрын
Hats off to you Broh... THANKS A MILLION 💙💙💙
@shshnk11
@shshnk11 Жыл бұрын
Brilliantly explained!!
@pratulyapratap9329
@pratulyapratap9329 8 ай бұрын
Maybe it will help :) int mid2 = left - mid1; // left = how many elements i can pickup mid1 = how many i have picked up
@9-1939
@9-1939 Ай бұрын
Best video. I watched twice and understood great effort and awesome solution 🔥🔥
@shashankarora2945
@shashankarora2945 2 ай бұрын
Explained so smoothly🔥🔥
@javabytharun
@javabytharun 2 ай бұрын
awesome explanation
@mayanksankhla1538
@mayanksankhla1538 Ай бұрын
Great Explanation! Just one observation, while explaining solution you considered median to be r1/r2 value in case of odd total length, so left part doesn’t include median, but in coding part you have considered median to be l1/l2 which mean left part includes median. Got little confused with that.
@umabharathis128
@umabharathis128 28 күн бұрын
Its very helpful and clearly understand...
@ketanjain5390
@ketanjain5390 Ай бұрын
beautifully explained!
@VikasSharma-eg8mc
@VikasSharma-eg8mc Жыл бұрын
Understood!! Amazing explanation
@charuprabha9696
@charuprabha9696 3 ай бұрын
This is a little bit too much for me to digest, but at least I understood most of it.🙂
@jaypratap3888
@jaypratap3888 5 ай бұрын
Thanks Bhai. Its a tough question, but explained it very nicely.
@atulanand6428
@atulanand6428 3 ай бұрын
I have also solved this but using another method: Approach was to iterate one smaller array from 1 to n and applying binary search and insert the element into another vector using bs.
@SHUBHAMSINGH-nv7ot
@SHUBHAMSINGH-nv7ot 6 ай бұрын
17:52 l1 is greater than r2 (correction)
@nitishjaswal7564
@nitishjaswal7564 Жыл бұрын
Thank you Striver sir 🥰
@arkadiptamojumder3800
@arkadiptamojumder3800 Жыл бұрын
l1 should be greater than r2 right at 17:49 ?
@faizanahmed9304
@faizanahmed9304 11 ай бұрын
Yup
@venkateshcharyakaram6547
@venkateshcharyakaram6547 6 күн бұрын
great explanation sir
@we_atheletes
@we_atheletes 10 ай бұрын
one of best video on yt
@45vinitthakkar56
@45vinitthakkar56 4 ай бұрын
hello
@mahakasthurim4998
@mahakasthurim4998 2 ай бұрын
Hi bro . Recently i started to watch your array playlist. Today i watching this median problem . I clearly understood your logic at first time itself . I really amazed with your logical thinking . How could you come up with this logic . You are making me logical thinking and programming more interesting. I am started to learn all the concept . Now i am following logic which is already there. But the way you are approaching all the problem with different optimal solution, its very unpredictable. Please provide some tips how you have build your logic on each ptogram when you started your coding journey. That would help most of the freshers. Thank you!
@NaveenBeniwal-c7z
@NaveenBeniwal-c7z 2 ай бұрын
your explanation is awesome 😇😇. Finally i can rest in peace🙃
@GoodLuck-dv2zu
@GoodLuck-dv2zu 6 ай бұрын
I think the time complexity is not the only reason why you should do a binary search on an array whose size is smaller. If you will do a binary search on the array with a bigger size, then you will not be able to construct the first array (left partition) to make two arrays asymmetrical
@techatnyc7320
@techatnyc7320 21 күн бұрын
Thanks Striver!!
@RGUKTEDUIN
@RGUKTEDUIN 8 ай бұрын
Understood salute to striver🤓
@joeljacob4685
@joeljacob4685 11 ай бұрын
Excellent explanation!!💌
@animeshkumar2683
@animeshkumar2683 Ай бұрын
Happy teachers day !!
@MohammadUmar-qn1sq
@MohammadUmar-qn1sq Ай бұрын
17:50 Its l1 > r2 :)
@nandini62
@nandini62 2 ай бұрын
Thank you so much broo for these series ☺️
@RohiniShankari
@RohiniShankari 2 ай бұрын
love your lectures
@MAHALAKSHMIVEERARAJ
@MAHALAKSHMIVEERARAJ Жыл бұрын
Wow explanations. Big Thanks to Striver.
@maneeshkumarpatel9874
@maneeshkumarpatel9874 3 ай бұрын
Loved this approach❤
@nayankhuman1043
@nayankhuman1043 2 ай бұрын
Understood 😊. You d best ❤
@AkOp-bf9vm
@AkOp-bf9vm 7 ай бұрын
why you taken 6 in limit , we have to take only five value???
@Ayush37262
@Ayush37262 7 ай бұрын
Same doubt, high = n1-1 kyu nhi hai?
@drishtirai864
@drishtirai864 2 ай бұрын
Thank you, Sir ! :)
@DhananjayKumar-bd2jg
@DhananjayKumar-bd2jg 8 ай бұрын
why can't we take this case to eliminate right? if(l1 > r2 || l2 > r1) high = mid - 1;
@abhinav7sinha
@abhinav7sinha 8 ай бұрын
This is a very nice video and possibly one of the best explanations. I just have one suggestion - because you're teaching this online, if you could speak softly, I am sure people would appreciate it. Right now, it seems like you're shouting. I wish you the best, don't take this comment harshly
@nishaaa_maurya
@nishaaa_maurya 6 ай бұрын
Hi Striver, It was a great explanation. Thank you !! Can you please explain that, why are taking first vector is always smaller?
@welcometoc.s.easpirants
@welcometoc.s.easpirants 6 ай бұрын
Great explanation. Thank you ❤
@anmolsaini2783
@anmolsaini2783 Ай бұрын
Understood...🙌
@empvaibhav9799
@empvaibhav9799 4 ай бұрын
The idea clicked the moment he said how many elemts to pick from both the arrays. Started coding it and damn it was tough to code it (edge cases 💀)
@harshpatel6615
@harshpatel6615 Ай бұрын
Understood
@sujeetiitd
@sujeetiitd 2 ай бұрын
At [17:23], you're picking 4 elements from the "Top" (not "Left"). Slips of the tongue make the matter very difficult to follow.
@shashank_0807
@shashank_0807 4 ай бұрын
Khatarnak but bhot kuch seekha !
@snehachauhan237
@snehachauhan237 3 ай бұрын
it was superb................
@Farhankhan-im3dv
@Farhankhan-im3dv 6 ай бұрын
the man is not just king he is a ginius
@YogaJournalWithMimansa
@YogaJournalWithMimansa 4 ай бұрын
Amazing Explanation! Thanks!
@souvikcseiitk
@souvikcseiitk 2 ай бұрын
this tutorial is awesome, thanks for this :)
@shikher4559
@shikher4559 3 ай бұрын
You are the best
@aryasharma69
@aryasharma69 Ай бұрын
From A2Z sheet i must say I've watched every video and found the approach best but unfortunately i was not able to consider this as the easy/optimal approach as in previous questions approach striver used to deliver us.
@oyeesharme
@oyeesharme Ай бұрын
understood bhaiya
@NazeerBashaShaik
@NazeerBashaShaik 5 ай бұрын
Understood, thank you.
@asmitraj4740
@asmitraj4740 Жыл бұрын
Finally Understood man.
@utkarshpawar8336
@utkarshpawar8336 Ай бұрын
@17.50 condition should be --- (l1 > r2) instead of (l1 > r1)
@beinginnit
@beinginnit Жыл бұрын
Thank you Striver💖💖
@SYCOA12CHAITANYAASOLE
@SYCOA12CHAITANYAASOLE 4 ай бұрын
Understood !! 😎😎
Bs-22. K-th element of two sorted arrays | Binary Search Approach
11:53
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,4 МЛН
когда не обедаешь в школе // EVA mash
00:51
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 21 МЛН
Man Mocks Wife's Exercise Routine, Faces Embarrassment at Work #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 6 МЛН
BS-18. Allocate Books or Book Allocation | Hard Binary Search
27:29
take U forward
Рет қаралды 168 М.
People said this experiment was impossible, so I tried it
34:49
Veritasium
Рет қаралды 1,7 МЛН
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 836 М.
ML Was Hard Until I Learned These 5 Secrets!
13:11
Boris Meinardus
Рет қаралды 313 М.
Median of two Sorted Arrays of Different Sizes | Binary Search
31:54
take U forward
Рет қаралды 240 М.
Median of Two Sorted Arrays - Binary Search - Leetcode 4
22:22
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 569 М.
BS-24. Search in a 2D Matrix - I | Binary Search of 2D
15:42
take U forward
Рет қаралды 104 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 658 М.
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,4 МЛН