Median of Two Sorted Arrays - Optimised Approach | Leetcode 4 Solution | Searching and Sorting

Sdílet
Vložit
  • čas přidán 25. 05. 2021
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
    1. Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
    Topic: #Array #leetcode4 #SearchingAndSorting
    Used #DataStructure: #Array
    #TimeComplexity: O(log(n+m))
    #SpaceComplexity: O(1)
    For detailed information and other exercises, VISIT: www.pepcoding.com
    Have a look at our result: www.pepcoding.com/placements​
    Follow us on our FB page: / pepcoding​
    Follow us on Instagram: / pepcoding​
    Follow us on LinkedIn: / pepcoding-education
    ----------------------------------------------------------------
    #BinarySearch #geeksforgeeks #SearchingAndSorting #leetcode4
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our CZcams page: / pepcoding
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education
    Follow us on Pinterest: / _created
    Follow us on Twitter: home
    .
    .
    .
    Happy Programming !!! Pep it up 😍🤩
    .
    .
    .
    #pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer

Komentáře • 118

  • @reshamsaharan1064
    @reshamsaharan1064 Před 3 lety +54

    Instructor put her heart and soul in explaining even the slightest intricacies in the problem. Hats off. These videos deserves much more views than it actually getting.

  • @deepakkapasia1
    @deepakkapasia1 Před rokem +3

    After reading so many blogs and posts for this post, This is the only video that can explain this question so well. Hats off to the instructor, feels like we are talking to the instructor while she is explaining.

  • @nitinkumar5974
    @nitinkumar5974 Před 2 lety +10

    I think this channel deserve more than 2-3 million subscribers

  • @learnersparadise7492
    @learnersparadise7492 Před rokem +5

    Someone give the my appreciation to this girl. She puts her heart into explaining. Well done 👍 and she is absolutely clear with the concept

  • @suryapratapsingh7130
    @suryapratapsingh7130 Před 2 lety +4

    Pepcoding has become my goto channel to understand Leetcode hard problems.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it.
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @ArcGaming07YT
    @ArcGaming07YT Před rokem +1

    pepcoding has best content for dsa over CZcams 🙌🏻

  • @jaiho5990
    @jaiho5990 Před 3 lety +20

    Pepcoding becomes my favorite after watching this vedio.. Amazing explanation !!!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber

  • @ojasvishwakarma9964
    @ojasvishwakarma9964 Před 2 lety +2

    There is no better explanation for this question than this on entire CZcams.

  • @darnavik2930
    @darnavik2930 Před rokem +1

    pepcoding explaination is the best over internet being it any DSA ques

  • @AmanGupta-eh4qs
    @AmanGupta-eh4qs Před rokem +5

    Pepcoding is an emotion of coders♥️🥺
    Thank you♥️

  • @beeramrahulreddy11
    @beeramrahulreddy11 Před 3 lety +11

    i think the complexity is log(min(m,n)) if we always try to do binarySearch on smaller array

  • @amriteshsingh2952
    @amriteshsingh2952 Před 3 lety +15

    This is the best explanation I have got after slogging this question after last 6 months. Best explanation ever.!!!!
    Thank you so much.

    • @Pepcoding
      @Pepcoding  Před 3 lety +3

      Glad it helped and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @user-ve5zv1pi7u
    @user-ve5zv1pi7u Před rokem +1

    Another best video from PepCoding.

  • @noobevsprorelation6838
    @noobevsprorelation6838 Před 2 lety +3

    Ooo great summet sir kae badh bhi koi itna accha samghaa . Wonderful

  • @AKASHKUMAR-li7li
    @AKASHKUMAR-li7li Před 3 měsíci +1

    Thank you for giving such a best explaination

  • @debbh274
    @debbh274 Před rokem +1

    Thank you for all the work you guys are doing.

  • @sunnygoswami2248
    @sunnygoswami2248 Před 2 lety +6

    This has been the best explanation ever for this question. Thankyou for your efforts Ma'am.

  • @YashSingh-ir3ec
    @YashSingh-ir3ec Před 2 lety +2

    Literally, East ho ya west only pepcoding is the best!

  • @4surajgo
    @4surajgo Před 2 lety +2

    This is the best explanation on youtube for this problem.

  • @drashtidoshi9685
    @drashtidoshi9685 Před rokem +1

    Thank you very much, ma'am! Your explanation was extraordinary.

  • @ShMayank
    @ShMayank Před rokem +1

    Best explanation online for this tricky problem. Pepcoding never disappoints.

  • @englishlnowledge486
    @englishlnowledge486 Před rokem +1

    Its a very detail and simpler explanation for this hard question, I saw 2 or 3 video but this one resolves all my doubts. Thank you

  • @rajattalnikar6507
    @rajattalnikar6507 Před rokem +1

    Beautiful Explanation manisha ji.

  • @satyamkumarrawat4573
    @satyamkumarrawat4573 Před rokem +1

    concept cleared like magic
    hats off to mam

  • @tsvmanojturlapati4492
    @tsvmanojturlapati4492 Před 2 lety +1

    Thanks A Lot Akka. ALMIGHTY bless you all with all kinds of wealth.

  • @nikhilgoyal8340
    @nikhilgoyal8340 Před 3 lety +2

    Amazingly explained. Pepcoding teachers are awesome :)

  • @codeblooded6760
    @codeblooded6760 Před 3 lety +12

    Maza aa gaya!! 🙌🏻 One more hard ques down!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @ashdavv
    @ashdavv Před 2 lety +2

    Great explanation , was struggling with the question . thanks

  • @kfg645
    @kfg645 Před rokem +1

    Best possible explanation.

  • @abdulsamad4149
    @abdulsamad4149 Před 3 lety +10

    This is excellent explanation. I would rather watch this type of longer videos over Family man season 2 :)

  • @navdeepsandhu7021
    @navdeepsandhu7021 Před rokem +1

    Great video! Great efforts Manisha

  • @akarshpaliwal4182
    @akarshpaliwal4182 Před 2 lety +2

    Awesome explanation, worth millions.

  • @sanheensethi9054
    @sanheensethi9054 Před 2 lety +7

    Such a nice explanation and I really appreciate that hardwork of pepcoding Team. In Future Pepcoding will become Big Brand.

  • @monikavaid5083
    @monikavaid5083 Před 2 lety +3

    after seeing multiple explanations i finally understood it from this one.

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad that it was helpful. For better experience and precisely arranged content visit on nados.io, also you can post your doubts on community tab on NADOS.

  • @mohibhussain2197
    @mohibhussain2197 Před 2 lety +1

    Amazing explanation !!!!!

  • @tarunsinghtomar8623
    @tarunsinghtomar8623 Před 3 lety +1

    Great Explanation ma'am!!

  • @dietpepsi7338
    @dietpepsi7338 Před 3 lety +1

    great teaching skills

  • @akshatsrivastava9015
    @akshatsrivastava9015 Před 3 lety +1

    Great explanation!!

  • @ankitjoshi2302
    @ankitjoshi2302 Před 2 lety +1

    Nice explanation Manisha🙂🙂

  • @nishantdhamija2880
    @nishantdhamija2880 Před 2 lety +1

    brilliant finally understood thanks

  • @vineetkumar2899
    @vineetkumar2899 Před rokem +1

    Amazing Explanation Ma'am😍

  • @vibhaypandey9650
    @vibhaypandey9650 Před rokem +1

    Awesome explanations

  • @nitishprasadkushwaha
    @nitishprasadkushwaha Před rokem +1

    God level explanation

  • @techwithrajdeep7633
    @techwithrajdeep7633 Před rokem +1

    Great Explanation

  • @lalitkashyap1203
    @lalitkashyap1203 Před rokem +1

    absolute gem

  • @priyankanarekar7983
    @priyankanarekar7983 Před 2 lety +1

    Create Maximum Number,Mini Parser,Longest Absolute File Path,Shortest Unsorted Continuous Subarray,Number of Atoms make a video on this ques of leetcode

  • @visakeswaran3620
    @visakeswaran3620 Před rokem

    the complexity is even more efficient its is log(min(m,n)) coz we do binarySearch on smaller array always

  • @sci-techwhatswhys1166
    @sci-techwhatswhys1166 Před 2 lety +1

    Thank you mam, awesome explaination

  • @user-uh3zr7mo4i
    @user-uh3zr7mo4i Před 3 lety +6

    Thank you for this amazing explanation Ma'am :)

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad it was helpful. keep motivating, keep learning and keep loving Pepcoding😊

  • @amansamal8233
    @amansamal8233 Před 2 lety +5

    Such an amazing expalanation it was thank you.

    • @Pepcoding
      @Pepcoding  Před 2 lety +2

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @ritikgupta1133
    @ritikgupta1133 Před rokem +1

    reminder :-if the total length(arr1length+arr2lenght) would have given that it can be 0 also then we would have to handle one more edge case also .here it is not given so code is working fine .

  • @udaypratapsingh8923
    @udaypratapsingh8923 Před rokem +1

    pep coding rocks

  • @anandkumar-ko5ok
    @anandkumar-ko5ok Před 3 lety +5

    great job, very detailed explanation

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad it was helpful! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @indranilchakraborty5949
    @indranilchakraborty5949 Před 2 lety +2

    mam ap explain krne ke time hi=a.length-1 kr rhe the....lekin code me achanak a.length kew kr die???????plz reply

  • @debbh274
    @debbh274 Před rokem +2

    Thanks

  • @shang_chi4651
    @shang_chi4651 Před 3 lety +6

    Great explanation 🔥🔥thanks a ton mam

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @namanagrawal4868
    @namanagrawal4868 Před 2 lety +1

    thanks alot :)

  • @nazreensheikh1256
    @nazreensheikh1256 Před 2 lety +4

    Such an amazing explanation 😍🤩

    • @Pepcoding
      @Pepcoding  Před 2 lety +1

      Glad you liked it:) To watch more such videos with better user experience go to nados.pepcoding.com

  • @anubhavmahajan230
    @anubhavmahajan230 Před 2 lety +2

    very nice explanation

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Thanks for liking. For better experience visit on nados.io

  • @suyashajain1541
    @suyashajain1541 Před rokem +1

    Great mam 🔥🔥

  • @tusharnain6652
    @tusharnain6652 Před 2 lety +1

    Mazaa aaya!

  • @utsavtaliyan7395
    @utsavtaliyan7395 Před 2 lety +4

    Important point 57:50

  • @nidhirathore7284
    @nidhirathore7284 Před 2 lety +1

    Thank you mam ❤

  • @abhinavagrawal6148
    @abhinavagrawal6148 Před 3 lety +3

    Very good explanation

  • @surbhikumari8443
    @surbhikumari8443 Před 2 lety +1

    Awesome explanation😊

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you think so! For better experience and well organised content sign up on nados.io and start learning.

  • @divyamgoel9183
    @divyamgoel9183 Před 2 lety +2

    Great video !!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you enjoyed it For better experience and well organised content sign up on nados.io and start learning.

  • @davidwarner325
    @davidwarner325 Před 2 lety

    [4]
    [1,2,3,5,6]
    this test case broke my code in leet code

  • @alfiyazahra4680
    @alfiyazahra4680 Před 3 lety +3

    You are the best

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

  • @nishantlakhara4127
    @nishantlakhara4127 Před 2 lety +1

    excellent explanation

    • @Pepcoding
      @Pepcoding  Před 2 lety

      We are glad that it was helpful for you. For better experience and precisely arranged content visit on nados.io

  • @shimeeaktarlaskar1463
    @shimeeaktarlaskar1463 Před 2 lety +2

    thank you so much

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @sanjana8267
    @sanjana8267 Před 2 lety +1

    We love you ma'am!

  • @arshadmanxoori07
    @arshadmanxoori07 Před rokem

    why we start segregation from (mid - 1) in array a

  • @shilpachaudhary9072
    @shilpachaudhary9072 Před měsícem

    low---0, high is 3 low+high/2= 1.5

  • @yourengineerbro
    @yourengineerbro Před 2 lety +2

    kya bat manisha didi

  • @shikhakejariwal86
    @shikhakejariwal86 Před 2 lety

    Where can I find the complete Java code?

  • @ashutoshkumar3300
    @ashutoshkumar3300 Před 2 lety +1

    Manisha mam bhi macha hi deti hai

  • @dheerajchhatani7610
    @dheerajchhatani7610 Před 3 lety +2

    greatttt

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @shilpachaudhary9072
    @shilpachaudhary9072 Před měsícem

    when you are trying calculate low=formula is low+high/2

  • @mickyman753
    @mickyman753 Před 2 lety +2

    This code will fail for testcase
    [1,2,3,5,6]
    [4]
    bleft goes -2 here after first iteration
    also when any array is of 0 length then too it fails
    both can be handled by using the smaller array as first array and check for both 0 length array condition

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Visit nados.pepcoding.com and sign up to NADOS, to clear your doubts and better experience.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @rohanraonallani561
    @rohanraonallani561 Před 3 lety +3

    Isn't the time complexity log(min(n,m))?

    • @rutabega306
      @rutabega306 Před 3 lety

      Correct! But maybe log(n+m) was simpler to write? And still fast enough that one needs to come up with the optimized algorithm...

  • @yoyo8293
    @yoyo8293 Před 2 lety

    why high = a.length and not high = (a.length+b.length)/2

  • @theuntoldtree
    @theuntoldtree Před 3 lety +6

    Bhaisaab 1hr

  • @abhay6124
    @abhay6124 Před rokem +1

    Vg

  • @jatinbhatoya8420
    @jatinbhatoya8420 Před 2 lety

    public static double findMedianSortedArrays(int[] arr1, int[] arr2) {
    if (arr2.length < arr1.length) return findMedianSortedArrays(arr2, arr1);
    int low = 0, high = arr1.length, n = arr1.length + arr2.length;
    while (low = 0 && cut1 - 1 < arr1.length ? arr1[cut1 - 1] : Integer.MIN_VALUE;
    int l2 = cut2 - 1 >= 0 && cut2 - 1 < arr2.length ? arr2[cut2 - 1] : Integer.MIN_VALUE;
    int r1 = cut1 >= 0 && cut1 < arr1.length ? arr1[cut1] : Integer.MAX_VALUE;
    int r2 = cut2 >= 0 && cut2 < arr2.length ? arr2[cut2] : Integer.MAX_VALUE;
    if (l1

  • @shilpachaudhary9072
    @shilpachaudhary9072 Před měsícem

    Why you saying 0+3/2 = 3 time is 48:29 minuts par
    low---0, high is 3 low+high/2= 1.5

  • @shaswatsingh
    @shaswatsingh Před 3 lety +1

    Ma'am not mam

  • @abhaybhatt7340
    @abhaybhatt7340 Před rokem

    test

  • @002ashishkumar5
    @002ashishkumar5 Před 2 lety +2

    very nice explanation

    • @Pepcoding
      @Pepcoding  Před 2 lety +1

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.