Binary Search : Median of two sorted arrays of different sizes.

In example 1 end should be 5(not 4) since there are total 5 elements.
Find median of two sorted arrays of different sizes. Algorithm is based on binary search.
github.com/mission-peace/inte...
/ tusharroy25

Пікірлер: 726

  • @shrimatkapoor2200
    @shrimatkapoor22003 жыл бұрын

    I love when he says "once it hits you" like some kind of drug or something

  • @alienwareCL

    @alienwareCL

    3 жыл бұрын

    @Kayden Khalil Lol, that is scam! fake accounts

  • @nishantkumar1149

    @nishantkumar1149

    3 жыл бұрын

    It's a better than a drug and the dopamine released on solving questions is sickkkk.

  • @JCatharsis

    @JCatharsis

    2 жыл бұрын

    It finally hit me I'm so high rn

  • @nikhileshkumar9126

    @nikhileshkumar9126

    2 жыл бұрын

    don't do drugs bro. It's harmful.

  • @ncba

    @ncba

    2 жыл бұрын

    Quite a common phrase

  • @nik220287
    @nik2202874 жыл бұрын

    Man the way you explained it in the first 5 minutes just clarified everything. Thanks. Great video!

  • @dakshays6375
    @dakshays63755 жыл бұрын

    Damn !!! How did anyone come up with such an Algorithm

  • @user-bv6bi2sz8r
    @user-bv6bi2sz8r5 жыл бұрын

    I was plagued by this problem for a very long time, you made it crystal clear, sir. Thank you!

  • @sshangrou8799
    @sshangrou87996 жыл бұрын

    thanks very much.it took me long time to think the algorithm on leetcode, your explanation is so clear and concise.Very nice

  • @maxfeldman6654
    @maxfeldman66546 жыл бұрын

    probably one of the best explanations i have seen so far, SUBSCRIBED!

  • @beer_bandhu
    @beer_bandhu6 жыл бұрын

    This is amazing. I was so confused by this problem, you explained it so succinctly. Thanks

  • @arthamsreenivas8858
    @arthamsreenivas88585 жыл бұрын

    Tushar Sir, you literally saved my time with crystal clear explanation on this problem.

  • @soulmusic6530
    @soulmusic65303 жыл бұрын

    after reading multiple explanations, this one finally made me understand how to think. Thanks for the video.

  • @user-vb2rm9hl9d
    @user-vb2rm9hl9d5 жыл бұрын

    this is the best explan I ve ever seen step by step with details, thank you

  • @DimpleSharma-jo9gf
    @DimpleSharma-jo9gf3 жыл бұрын

    Such a great explanation! Love how you simplify things. Thanks a lot!!!

  • @35sherminator
    @35sherminator5 жыл бұрын

    Legendary. Very crisp and clear approach. Thank you very very much!

  • @yoosufahmadh3945
    @yoosufahmadh39454 жыл бұрын

    Repeat watching the first 6 minutes until you get it. Totally helps. Thank you so much. You simply put it

  • @kimmeng6939
    @kimmeng69395 жыл бұрын

    7:18 end should be 5 not 4 because we are searching which position we want to cut.

  • @prakashtiwari7834

    @prakashtiwari7834

    4 жыл бұрын

    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.

  • @everydayleetcode2961

    @everydayleetcode2961

    4 жыл бұрын

    @@prakashtiwari7834 I was wondering why did he take end as 4 and read this comment ! Thanks a lot !

  • @emilyhuang2759

    @emilyhuang2759

    4 жыл бұрын

    But why not 4? The 5th index is empty....so I would think the end is 4...?

  • @sharmamukul938

    @sharmamukul938

    3 жыл бұрын

    @@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.

  • @varunwalia95

    @varunwalia95

    3 жыл бұрын

    @@sharmamukul938 it should be the size of the array not index that is to be taken as high element according to code.

  • @marshallxu7480
    @marshallxu74804 жыл бұрын

    this is the best video of all time, it brings happiness. thank you!

  • @sanjayizardar2263
    @sanjayizardar22634 жыл бұрын

    Perfectly explained... Found most useful among all the available videos on KZread for median in two sorted arrays.

  • @dongshuowu3454
    @dongshuowu34545 жыл бұрын

    Thank you for the wonderful video. I was stuck for a long time until you made it co clear to me.

  • @balajim7801
    @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.

  • @eskuAdradit0

    @eskuAdradit0

    3 жыл бұрын

    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?

  • @haoyuwu894

    @haoyuwu894

    2 жыл бұрын

    @@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.

  • @abhijeetpatnaik5494
    @abhijeetpatnaik54942 жыл бұрын

    I can't stress enough, how clear this video explanation is. Really loving your work, and it's very very helpful.

  • @JaySolanki91
    @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.

  • @zaheenrahman6608
    @zaheenrahman66086 жыл бұрын

    My boy Tushar Roy! Earned yourself a sub! Gonna help my algo course so much

  • @dzungdev
    @dzungdev4 жыл бұрын

    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.

  • @rkalyankumar
    @rkalyankumar2 жыл бұрын

    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!

  • @saurabhzalke4232
    @saurabhzalke42323 жыл бұрын

    So elegant and simple. One of the best tutorial ever! Keep it up.

  • @hawaijarjs7496
    @hawaijarjs74963 жыл бұрын

    Thanks Bro for the excellent explanation! It is crystal clear now how the logic works for both odd/even scenarios. Appreciate your time. Cheers!

  • @bewareofnikhil
    @bewareofnikhil Жыл бұрын

    What a precise and correct explanation of the algorithm! Thanks for making and sharing this video, Tushar.

  • @remixisthis
    @remixisthis5 жыл бұрын

    Very well done detailed explanation. Much better than the LeetCode solution example. Thanks for taking the time to make this!

  • @pawandeepchor89
    @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 !!

  • @suvirsaurav5587
    @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.

  • @harishgovindan
    @harishgovindan4 жыл бұрын

    Excellent video! Quite precise and covers all aspects! Thank you!

  • @barmalini
    @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

  • @rogerwhite8061
    @rogerwhite80615 жыл бұрын

    Best explanation of this challenge I have found, thank you so much

  • @anondoggo
    @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!

  • @simingye7502
    @simingye75025 жыл бұрын

    Best explanation I have ever seen! Thank you!

  • @MohitSinha4
    @MohitSinha44 жыл бұрын

    Wow, your explanations are just great! Thank you so much!

  • @matthkang
    @matthkang5 жыл бұрын

    Thank you for making it clear and easy to understand!

  • @video-vocabulary
    @video-vocabulary3 жыл бұрын

    00:00 Introduction 01:39 Solution 06:19 Example 1 14:35 Example 2 20:11 Code

  • @abhinavgarg5611

    @abhinavgarg5611

    3 жыл бұрын

    Thanks buddy😊

  • @ADITYAKUMAR-yd3ow
    @ADITYAKUMAR-yd3ow6 жыл бұрын

    Perfect explanation, initially I though it would be difficult for me. But gradually you made me understand in only one go. Thanks 😀

  • @tusharroy2525

    @tusharroy2525

    6 жыл бұрын

    Great.

  • @dragonflyboss7162
    @dragonflyboss71624 жыл бұрын

    This explanation is so detailed, thank you!

  • @sanjitselvan5348
    @sanjitselvan5348 Жыл бұрын

    I went through 5 videos before landing here and finally understanding the intuition behind the solution. Thank you!

  • @double_courage57
    @double_courage573 жыл бұрын

    @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!

  • @TheBuzoTechie

    @TheBuzoTechie

    2 жыл бұрын

    thanks for the extra intuition :)

  • @return1210

    @return1210

    Жыл бұрын

    Thanks a lot!

  • @akshaysuman8168
    @akshaysuman81686 жыл бұрын

    Its so nice to see you back

  • @rushivt
    @rushivt23 күн бұрын

    I have seen many other videos for this problem, but yours is the one that made me follow every step clearly. Thank you!

  • @Chandan-io3jm
    @Chandan-io3jm6 жыл бұрын

    Best Channel for Data Structure && Algorithms !

  • @VishalSharma-hq5ti
    @VishalSharma-hq5ti4 жыл бұрын

    Once again a Masterpiece!

  • @shwetankgupta
    @shwetankgupta5 жыл бұрын

    Finally, I understood the crux of this problem. Thanks for the enlightenment.

  • @VishwajeetPandeyGV
    @VishwajeetPandeyGV5 жыл бұрын

    Thanks for this. You made it very clear & easy & fast to understand

  • @vishnup3182
    @vishnup31824 жыл бұрын

    Best explanation found so far. Thanks !

  • @vladn.2332
    @vladn.23326 жыл бұрын

    Very clear and good explanation. Thank you very much, Tushar!

  • @somiljain896
    @somiljain896Ай бұрын

    The best explaination with perfect testcases that I found for this question on Internet. Thank you!

  • @SonuSonu-tk5pk
    @SonuSonu-tk5pk6 жыл бұрын

    very neat and excellent explanation

  • @tusharroy2525

    @tusharroy2525

    6 жыл бұрын

    Thanks

  • @juliahamilton3493
    @juliahamilton34934 жыл бұрын

    Thank you so much for explaining the algorithm! Very clear!

  • @jinny5025
    @jinny50253 жыл бұрын

    wow there's nothing more than clearer than this! thanks :) you just saved my time

  • @gauravdudeja
    @gauravdudeja6 жыл бұрын

    After watching 2 times it quite easy to understand. Keep up the good work Tushar.

  • @wengao6544
    @wengao6544 Жыл бұрын

    This video is definitely the most effective one in providing a clear explanation of the algorithm

  • @someshkumargupta5053
    @someshkumargupta50536 жыл бұрын

    Finally!! Thank you so much !

  • @mccloud35
    @mccloud356 жыл бұрын

    This explanation is fantastic. Great job Tushar!

  • @shaziasamreen8584
    @shaziasamreen85843 жыл бұрын

    Even after 5 years your video is best for this problem.Thank you so much for wonderful Explaination

  • @meganlee5897
    @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

  • @umairalvi7382
    @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

  • @SourabhCA
    @SourabhCA4 жыл бұрын

    Spent a lot of time trying to understand this from leetcode solutions and discussion. And you video explained it in 5 minutes

  • @Priyankachauhan-qv2rx
    @Priyankachauhan-qv2rx4 жыл бұрын

    Hey Tushar, You make complicated problem look so simple and easy. Awesome job.

  • @sravanthikanchi5362
    @sravanthikanchi53626 жыл бұрын

    Thanks a lot for this ! Awesome explanation !

  • @achyutaarjunneupane1154
    @achyutaarjunneupane11546 жыл бұрын

    great sir, got it in single explanation, I looked all over for over 4 hr

  • @tusharroy2525

    @tusharroy2525

    6 жыл бұрын

    +achyut aarjunneupane nice

  • @alejandrofarias7320
    @alejandrofarias73205 жыл бұрын

    Very good videos. You are great instructor. Cheers from México.

  • @user-ts9ji6fq9d
    @user-ts9ji6fq9d3 жыл бұрын

    I can never figure it out without this video.

  • @kumarsamaksha7207

    @kumarsamaksha7207

    3 жыл бұрын

    noob

  • @biswajeetchatterjee4721
    @biswajeetchatterjee47215 жыл бұрын

    Thanks Tushar.. Your videos really help to understand complex algos.. Keep it up and keep posting videos like this :)

  • @jimz2392
    @jimz23925 жыл бұрын

    Thank you Tushar, your video helps me a lot!

  • @shashankshekharkaushik1567
    @shashankshekharkaushik15672 жыл бұрын

    I was so confuse how to solve this without taking care of corner cases as extra, your explanation was awesome. Thanks

  • @jessica_1811
    @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.

  • @360nickx
    @360nickx4 жыл бұрын

    Excellent Break down. Much appreciated.

  • @nandanimadhukar
    @nandanimadhukar3 жыл бұрын

    Great explanation with ample examples! Keep up the good work

  • @NeoMennon
    @NeoMennon5 жыл бұрын

    Tushar you are awesome! I have watched few video about this question, yours is the most intuitive one

  • @krishna0908
    @krishna09086 жыл бұрын

    Excellent explanation, great clarity. Thanks Tushar.

  • @user-hr1tx7bo1w
    @user-hr1tx7bo1w5 жыл бұрын

    Thank you, it's very helpful.

  • @yiming6759
    @yiming67595 жыл бұрын

    Thank you this is really easy to follow!

  • @sindhusp8935
    @sindhusp89353 жыл бұрын

    This is such a neat algo! thanks for the explanation

  • @prashanthvaidya5220
    @prashanthvaidya52206 жыл бұрын

    Very well explained. THANKYOU! :)

  • @j50313j50313
    @j50313j503134 жыл бұрын

    You save my life. Just watch for 8 minutes and come up with a solution by myself!

  • @vishnu_bhatt
    @vishnu_bhatt6 жыл бұрын

    Helped a lot bro.Thank you for such good explanations.

  • @ahasunos5914
    @ahasunos59142 жыл бұрын

    Thank you so much Tushar. This explanation will last for generations.

  • @jayachandrann6825
    @jayachandrann68256 жыл бұрын

    Perfect explanation, thanks for your hard work !!!...

  • @jaatharsh
    @jaatharsh3 жыл бұрын

    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_

    @CodingWithPrakash_

    3 жыл бұрын

    kzread.info/dash/bejne/iWGJw86zibmrmbQ.html

  • @kulkarnianiket929
    @kulkarnianiket9295 жыл бұрын

    Great video! I think you need to divide by 2.0 on line 46. It failed when I ran it with input1 as [1,2] and input2 [3,4].

  • @vishwajeetpawar5074
    @vishwajeetpawar50742 жыл бұрын

    Thanks Tushar.Your explanation helped a lot to understand the depth of logic and algorithm behind this question.

  • @lukaslehmann9708
    @lukaslehmann9708 Жыл бұрын

    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.

  • @junjiechen7341
    @junjiechen73416 жыл бұрын

    Very down to earth explaination.

  • @rapetiraviteja3678
    @rapetiraviteja36784 жыл бұрын

    elegant explanation! thank you Tushar :D

  • @vinayybhore
    @vinayybhore6 жыл бұрын

    Excellent Solution and the best so far explanation for this problem on youtube :)

  • @ehsona1827
    @ehsona18274 жыл бұрын

    the way the problem was broken down, amazing solution.

  • @johnnylasers
    @johnnylasers6 жыл бұрын

    Nicely done, sir!

  • @Destiny22377
    @Destiny223774 жыл бұрын

    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

  • @feisuxiaozhu
    @feisuxiaozhu5 жыл бұрын

    simply fantastic, thanks!

  • @techbarikcom
    @techbarikcom4 жыл бұрын

    You are making my life a lot easier! May God bless you

  • @binhengluo8674
    @binhengluo86743 жыл бұрын

    Great demo! Thank you!

  • @bharathik6479
    @bharathik64794 жыл бұрын

    Crystal clear explanation , Bro. You are helping a lot of people, Please Keep up the good Work.

  • @kumarann3483
    @kumarann34835 жыл бұрын

    clear explanation and concise code, good work!

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk6 жыл бұрын

    Beautiful Explanation Thank You :)

  • @emilyhuang2759
    @emilyhuang27594 жыл бұрын

    7:21 What do you mean by +1 allows what to "play well with both odd and even number of elements in the combines array"?

  • @CinghAnkit

    @CinghAnkit

    4 жыл бұрын

    So that we have extra element on the left side , where we are looking for median. listen from 9:59 ,it might help you.

  • @tvbuff
    @tvbuff2 жыл бұрын

    You truly are making coding simple !