Man the way you explained it in the first 5 minutes just clarified everything. Thanks. Great video!
@meganlee58974 жыл бұрын
Brilliant video and explanation! One minor change to the 1st example:initialization: 1) pick smaller len 2) start = 0, end = len, binary search the len of left size of X e.g with the first example: 1st round lo = 0, hi = 5, mid = lo + (hi - lo) / 2 = 2 2nd round lo = mid + 1 = 3, hi = 5
@shaziasamreen85843 жыл бұрын
Even after 5 years your video is best for this problem.Thank you so much for wonderful Explaination
@barmalini5 жыл бұрын
I paused the video at 20:12 and now going to solve the problem at leetcode myself, thank you so much Tushar, your help for the rest of us who have never graduated from the CS but still want to become a sane programmer is invaluable
@dakshays63755 жыл бұрын
Damn !!! How did anyone come up with such an Algorithm
@程龙-b1w5 жыл бұрын
I was plagued by this problem for a very long time, you made it crystal clear, sir. Thank you!
@jessica_1811 Жыл бұрын
came to "like" this video only found out that I have "liked" this video 4 years ago when I was looking for my last job. Thank you Tushar.
@rushivt4 ай бұрын
I have seen many other videos for this problem, but yours is the one that made me follow every step clearly. Thank you!
@umairalvi73824 жыл бұрын
People like me wouldnt understand this video in one time,you gotta watch it multiple times ,read about the problem solving strategy then you will get the problem. He has explained in a very good manner
@shrimatkapoor22004 жыл бұрын
I love when he says "once it hits you" like some kind of drug or something
@Alex7nt3 жыл бұрын
@Kayden Khalil Lol, that is scam! fake accounts
@nishantkumar11493 жыл бұрын
It's a better than a drug and the dopamine released on solving questions is sickkkk.
@JCatharsis3 жыл бұрын
It finally hit me I'm so high rn
@nikhileshkumar91263 жыл бұрын
don't do drugs bro. It's harmful.
@ncba2 жыл бұрын
Quite a common phrase
@abhijeetpatnaik54942 жыл бұрын
I can't stress enough, how clear this video explanation is. Really loving your work, and it's very very helpful.
@DonchenkoNadia3 жыл бұрын
Tushar, thank you so much! You explained it perfectly! If someone need solution in Python, here it is: class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: if len(nums1) > len(nums2): return self.findMedianSortedArrays(nums2, nums1); x = len(nums1) y = len(nums2) low = 0 high = x while low
@gunahawk68932 жыл бұрын
clean implementation good job
@beer_bandhu6 жыл бұрын
This is amazing. I was so confused by this problem, you explained it so succinctly. Thanks
@soulmusic65304 жыл бұрын
after reading multiple explanations, this one finally made me understand how to think. Thanks for the video.
@double_courage574 жыл бұрын
@4:30 - I took a second to understand this : Think of the final sorted array (without duplicates) and draw a median line. We need to find the average of numbers which are immediately to the left and right of that median line. If x2 is immediately to the left of the median line, it has to be greater than y5 (remember final array is sorted). Similarly, if y6 is to the right of the median line it has to be lesser than x3. Hope this helps someone!
@TheBuzoTechie2 жыл бұрын
thanks for the extra intuition :)
@return1210 Жыл бұрын
Thanks a lot!
@sanjitselvan5348 Жыл бұрын
I went through 5 videos before landing here and finally understanding the intuition behind the solution. Thank you!
@wengao6544 Жыл бұрын
This video is definitely the most effective one in providing a clear explanation of the algorithm
@uzdik.student3 жыл бұрын
00:00 Introduction 01:39 Solution 06:19 Example 1 14:35 Example 2 20:11 Code
@abhinavgarg56113 жыл бұрын
Thanks buddy😊
@marshallxu74804 жыл бұрын
this is the best video of all time, it brings happiness. thank you!
@remixisthis5 жыл бұрын
Very well done detailed explanation. Much better than the LeetCode solution example. Thanks for taking the time to make this!
@balajim78014 жыл бұрын
Clear explanation. Thanks. A small error, 8:33 value of "end" should be 5 (size of small array). I followed just your example and coded, everything was right but failing always, until I watched your code & realized that end should have initial value of smallest array's length.
@eskuAdradit03 жыл бұрын
any clear explanation on why would we do it like this? is it the same reasoning behind adding + 1 to the sum of both arrays before dividing by two?
@haoyuwu8942 жыл бұрын
@@eskuAdradit0 I think it's because in some cases we can have all the elements in x on the left side. He mentioned that partitionX is "the number of elements partitioned to the left in x." So in those cases, partitionX can be the size of the small array. Consider this example: arrayX: [1, 2, 3, 4] and arrayY: [5, 6, 7, 8]. All the elements in x are smaller than elements in y. Hope this helps.
@rkalyankumar3 жыл бұрын
The best possible explanation of the problem I've seen so far. I have now clear idea on how median of two sorted array algorithm works using binary search & partitioning arrays. Good stuff!
@SourabhCA5 жыл бұрын
Spent a lot of time trying to understand this from leetcode solutions and discussion. And you video explained it in 5 minutes
@ADITYAKUMAR-yd3ow7 жыл бұрын
Perfect explanation, initially I though it would be difficult for me. But gradually you made me understand in only one go. Thanks 😀
@tusharroy25257 жыл бұрын
Great.
@anondoggo2 жыл бұрын
Beautiful solution, thank you so much! I can't believe how close I was to the solution, I wished I pushed myself a bit harder, but this was a great educational experience. Thanks again!
@suvirsaurav55875 жыл бұрын
In the first example, the end value at the start should be 5 as we can have a partition when all the 5 elements of array X will be on the left side.
@yoosufahmadh39454 жыл бұрын
Repeat watching the first 6 minutes until you get it. Totally helps. Thank you so much. You simply put it
@kimmeng69395 жыл бұрын
7:18 end should be 5 not 4 because we are searching which position we want to cut.
@prakashtiwari78344 жыл бұрын
YES! Had the last element of first array been 10 instead of 15, the algorithm would've broken at 13:45. Anyways, the explanation was awesome.
@everydayleetcode29614 жыл бұрын
@@prakashtiwari7834 I was wondering why did he take end as 4 and read this comment ! Thanks a lot !
@emilyhuang27594 жыл бұрын
But why not 4? The 5th index is empty....so I would think the end is 4...?
@sharmamukul9384 жыл бұрын
@@emilyhuang2759 Exactly even i'm not able to figure out why the end should be 5 and not 4 as it is clearly mentioned in the video that first array has 5 elements in total.
@varunwalia953 жыл бұрын
@@sharmamukul938 it should be the size of the array not index that is to be taken as high element according to code.
@maxfeldman66546 жыл бұрын
probably one of the best explanations i have seen so far, SUBSCRIBED!
@Destiny223775 жыл бұрын
Great solution. Not every detail was explained but as everyone else was saying this is probably the best solution on the net and if not it is one of the best ! The missing details can be inferred
@bewareofnikhil2 жыл бұрын
What a precise and correct explanation of the algorithm! Thanks for making and sharing this video, Tushar.
@somiljain8965 ай бұрын
The best explaination with perfect testcases that I found for this question on Internet. Thank you!
@sshangrou87996 жыл бұрын
thanks very much.it took me long time to think the algorithm on leetcode, your explanation is so clear and concise.Very nice
@arthamsreenivas88585 жыл бұрын
Tushar Sir, you literally saved my time with crystal clear explanation on this problem.
@gauravghosh6562 Жыл бұрын
this is the best channel for coding hand down
@saurabhzalke42324 жыл бұрын
So elegant and simple. One of the best tutorial ever! Keep it up.
@jaatharsh4 жыл бұрын
don't think there are words to express my gratitude towards your hard work in making such bloody awesome videos @TusharRoy your videos indeed are class apart & blessing for someone who wants to gain in-depth knowledge on DSA.
@CodingWithPrakash_4 жыл бұрын
kzbin.info/www/bejne/jV64kp-wjrt4n7M
@stanleyakachukwu78812 жыл бұрын
Brother, you have done well in explaining this. Thanks! I wanted to abandon this until I saw your video. With what I have known now I can go and write it myself until I pass it without looking at random solutions across the internet. I have subscribed for more.
@ahasunos59143 жыл бұрын
Thank you so much Tushar. This explanation will last for generations.
@sanjayizardar22634 жыл бұрын
Perfectly explained... Found most useful among all the available videos on KZbin for median in two sorted arrays.
@PhoenixRisingFromAshes4714 жыл бұрын
Jahapana tussi great .........sir i read a lot about this problem solution everywhere but finally came to understand from your video only...you made a very tricky concept so simple to understand
@seekingWisdomAcrossWorlds3 жыл бұрын
I was so confuse how to solve this without taking care of corner cases as extra, your explanation was awesome. Thanks
@vikasaggarwal28342 жыл бұрын
i usually don't comments on videos but your method of explaining made me comment on this... Superb video boss..
@李克弱5 жыл бұрын
this is the best explan I ve ever seen step by step with details, thank you
@achyutaarjunneupane11547 жыл бұрын
great sir, got it in single explanation, I looked all over for over 4 hr
@tusharroy25257 жыл бұрын
+achyut aarjunneupane nice
@j50313j503134 жыл бұрын
You save my life. Just watch for 8 minutes and come up with a solution by myself!
@pawandeepchor896 жыл бұрын
Excellent !! Nothing more one can do to explain this problem :) Thanks for sharing it buddy !! You are a star, keep up the good work, cheers !!
@Chandan-io3jm7 жыл бұрын
Best Channel for Data Structure && Algorithms !
@shwetankgupta5 жыл бұрын
Finally, I understood the crux of this problem. Thanks for the enlightenment.
@韓覲3 жыл бұрын
I can never figure it out without this video.
@kumarsamaksha72073 жыл бұрын
noob
@mukut5ul3 жыл бұрын
These videos are great equivalent to full computer science degree content
@stratonov2 жыл бұрын
Beautiful lovely brilliantly handled edge cases
@sharatchandra91984 жыл бұрын
Most Beautiful explanation and solution. My deepest gratitude to all your videos.
@bharathik64794 жыл бұрын
Crystal clear explanation , Bro. You are helping a lot of people, Please Keep up the good Work.
@vishwajeetpawar50743 жыл бұрын
Thanks Tushar.Your explanation helped a lot to understand the depth of logic and algorithm behind this question.
@dongshuowu34545 жыл бұрын
Thank you for the wonderful video. I was stuck for a long time until you made it co clear to me.
@subhodeepganguly25754 жыл бұрын
Very Nice Explanation. One of the best videos of Tushar
@dzungdev5 жыл бұрын
Thank you very much for your great explanation. I learn a lot from you, not only the code but the way to explain the problem.
@MykolaDolgalov4 жыл бұрын
*EDIT:* Thank you for the video. I watched it carefully, then coded the solution from memory. And then I compared to your solution, and mine is a little simpler and easier to understand (code is in the first comment). *Initial comment* 14:41 here it is obvious from the data that we must compare the rightmost and leftmost elements to see if the values in the arrays even overlap in range. If they don't we should skip the binary search and just treat them as one continuous sorted array, and find the median in it directly. Thank you for the wonderful videos.
@MykolaDolgalov4 жыл бұрын
A somewhat simpler and easier to follow code: public double findMedianSortedArrays(int[] nums1, int[] nums2) { int len1 = nums1.length; int len2 = nums2.length; int res = 0; if(len2 < len1) return findMedianSortedArrays(nums2, nums1); int partitionX = len1 / 2; int low = 0; int high = len1; while(low 0 ? nums1[partitionX - 1] : Integer.MIN_VALUE; int num1R = partitionX < len1 ? nums1[partitionX] : Integer.MAX_VALUE; int num2L = partitionY > 0 ? nums2[partitionY - 1] : Integer.MIN_VALUE; int num2R = partitionY < len2 ? nums2[partitionY] : Integer.MAX_VALUE; if(num1L = num2L) { // found correct comb if((len1 + len2) % 2 != 0) return Math.max(num1L, num2L); else return 1.0*(Math.max(num1L, num2L) + Math.min(num1R, num2R)) / 2.0; } else if(num1R < num2L) { // need to move to the right low = ++partitionX; } else high = --partitionX; } return Double.MIN_VALUE; }
@techbarikcom4 жыл бұрын
You are making my life a lot easier! May God bless you
@himangshubiswas542 Жыл бұрын
Because of you I am going to solve this problem otherwise I thought I will skip it, thank you
@tvbuff3 жыл бұрын
You truly are making coding simple !
@zaheenrahman66086 жыл бұрын
My boy Tushar Roy! Earned yourself a sub! Gonna help my algo course so much
@ankush3634 жыл бұрын
I got asked this question in an interview .Before this video i ignored this question multiple times due to which i was not able to answer this in interview .After getting rejected from the interview i came here and i feel how can a person come up with such a solution in 45 minute interview and code it properly.But The solution is very nice.
@CodingWithPrakash_4 жыл бұрын
kzbin.info/www/bejne/jV64kp-wjrt4n7M
@lukaslehmann97082 жыл бұрын
Hi Sir, thanks for your great and detailed explanation...just had watched serveral videos and explanations before I saw your video...and finally I understood how it worked...It is really awsome that you used these examples to illustrate the problem (including the edge case) and in your code you also wrote so many annotations...I really appreciate your effort and great work.
@rahul-patil5 жыл бұрын
15:24 If there are n element then we can partition that array in n+1 no. of ways. E.G 4 elements then we partition it in. 1) 0 - 4 2) 1 - 3 3) 2 - 2 4) 3 - 1 5) 4 - 0
@krishnabhagavan96214 жыл бұрын
0-4 and 4-0 results in same arrays
@ИванЕлисеев-р1з3 жыл бұрын
Thank you so much. Your explanation is the best. Only with you I understood how to solve that problem.
@nabidulalam69564 жыл бұрын
Simple and elegant explanation. Hats off.
@DimpleSharma-jo9gf4 жыл бұрын
Such a great explanation! Love how you simplify things. Thanks a lot!!!
@gauravdudeja6 жыл бұрын
After watching 2 times it quite easy to understand. Keep up the good work Tushar.
@hawaijarjs74964 жыл бұрын
Thanks Bro for the excellent explanation! It is crystal clear now how the logic works for both odd/even scenarios. Appreciate your time. Cheers!
@pi3ni02 жыл бұрын
Thanks, good explanation. I was looking for different resources, but it was the best so far :)
@semurgx3 жыл бұрын
this one of the best explanation on youtube, awesome!
@35sherminator5 жыл бұрын
Legendary. Very crisp and clear approach. Thank you very very much!
@കള്ള_ചക്കോ3 жыл бұрын
give this man a medal
@Avinashkumar-xt4zq3 жыл бұрын
Best explanation present on the Internet!
@JaySolanki915 жыл бұрын
Simply Amazing !!! This algorithm was really helpful and you gave good examples to solve it. Especially the one in which you covered the corner cases.
@_PRITIJHA4 жыл бұрын
Your channel solves all my doubt
@kshitijtakarkhede78334 ай бұрын
Crystal clear sir
@WS-lv4kk5 жыл бұрын
For odd total array size, instead of adding 1 in the (x+y+1)/2 and taking the max of the left half, I think you can just do (x+y)/2 and take min of the right half.
@pavithranravichandiran67202 жыл бұрын
Great observation!
@mrinmoypaul68103 жыл бұрын
Tushar Sir tumi Bhogowan, Love from West Bengal
@RITIKSINGH-re5ne3 жыл бұрын
The explanation so deep I forgot what was the question.
@SonuSonu-tk5pk7 жыл бұрын
very neat and excellent explanation
@tusharroy25257 жыл бұрын
Thanks
@niksmachnih2642 жыл бұрын
The best explanation that I ever heard
@shashikantdivekar78393 жыл бұрын
Very good explanation. Thank you Tushar Roy.
@priyanka.sarkar6 жыл бұрын
Hats off sir...I am really overwhelmed by the way you explained this algorithm and made it so easy and simple...(y) Thank you so much...:-)
@jinny50254 жыл бұрын
wow there's nothing more than clearer than this! thanks :) you just saved my time
@priyankachauhan01125 жыл бұрын
Hey Tushar, You make complicated problem look so simple and easy. Awesome job.
@neerajlajpal88584 жыл бұрын
Amazing video. Clear and concise explanation
@133790563 жыл бұрын
With brute force you can actually achieve O((m+n)/2) with constant space. Just don't store the merged elements and end the merge once your reach the m+n/2 element
@deleteduser792ba2 жыл бұрын
That is true but there is no such thing as O((m+n)/2) since 1/2 is a constant and it gets eradicated in the asymptotic analysis. Nonetheless, what you have proposed is a "better" linear solution.
@msteja3 жыл бұрын
Geniusly explained the algo 🙏🏻👏🏻
@siddharthkhandelwal933 Жыл бұрын
Very well explained, the code is very clear and precise. Thanks
@DhananjayTyagi245 жыл бұрын
The best explanation so far.
@NeoMennon5 жыл бұрын
Tushar you are awesome! I have watched few video about this question, yours is the most intuitive one
@ujjvalsharma50553 жыл бұрын
One of the best explaination!!. Great work. Keep making more video :)
@kalashnikov2034 жыл бұрын
The best explanation on this topic.
@rajasekharmaddineni10694 жыл бұрын
To move left or Right of array, should increase or decrease on "start" and "end" variables. not partition x because it's failing in below case [1,2,3,4,6] [5]
@GeetThaker4 жыл бұрын
it is working. remember you have to make 2nd array as X in example.
@jacobstech17773 жыл бұрын
Simply the best explanation.
@depression_plusplus6120 Жыл бұрын
If you're reading this...and belong to non cs branch...i really really hope and pray to god that you end up successful with a good job at the end, unlike me. Who always strived hard, did over 1200+ question. Cracked till interview, but always got rejected because of my branch or becoz of communication skills...i hope that never happens to you atleast! They say, "Prayers and curses of a hurt sad person never go unlistened". I hope my prayers becomes a blessing for you!...
@depression_plusplus612010 ай бұрын
Bro...just give up... you're no good...just do anything at this point...forget coding😂😂
@abhinavmiglani65875 жыл бұрын
The variable end should be input length of nums 1, Consider case: nums1 = [1, 3] nums2 = [2]