BS 21: Median of two Sorted Arrays of Different Sizes | Brute and Better Approach

Sdílet
Vložit
  • čas přidán 14. 10. 2024
  • Please watch our new video on the same topic: • BS-21. Median of two S...
    Check our Website:
    Notes: • BS-21. Median of two S...

Komentáře • 73

  • @takeUforward
    @takeUforward  Před rokem +12

    Please watch our new video on the same topic: czcams.com/video/F9c7LpRZWVQ/video.html

  • @balakrishnanr648
    @balakrishnanr648 Před rokem +48

    15:47 - for better SEO.
    This is why I like striver RAJ, Straightforward, upto point and honest.
    Really good to be like that, helps in longer run.

  • @rushidesai2836
    @rushidesai2836 Před 4 měsíci +11

    This better approach is pretty smart I must say. Array is visualized just using two variables, amazing.

  • @amitranjan6998
    @amitranjan6998 Před rokem +29

    It's the hard problem on leetcode and you solved it brilliantly , hats off !!

  • @mohit5963
    @mohit5963 Před rokem +2

    you expain it in a such easy manner, so good Striver...

  • @pratyushtripathi1728
    @pratyushtripathi1728 Před 11 měsíci +7

    बहुत सही गुरु जी जलवा है आपका 😂

  • @cinime
    @cinime Před rokem +5

    Understood! Super wonderful explanation as always, thank you very very much for your effort!!

  • @kaichang8186
    @kaichang8186 Před 5 dny

    understood, thanks for the perfect explanation

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

    UnderStood, Wanted to learn this from a long long time.

  • @stith_pragya
    @stith_pragya Před 7 měsíci +1

    Thank You Much for this wonderful video...................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @rupeshpatil6957
    @rupeshpatil6957 Před 18 dny

    Thanks bro ...........But still having O(N+M) time complexity. Need further improvements.

  • @dineshdsv7815
    @dineshdsv7815 Před 10 měsíci +2

    Thanks for the detailed explanation

  • @001_bajpai5
    @001_bajpai5 Před 9 měsíci +2

    If You do this bruteforce in Pyhton language then your all test cases will pass
    python is really good language

  • @smrutisitikanta2664
    @smrutisitikanta2664 Před 2 měsíci

    What a brilliant approach!!!

  • @dewanandkumar8589
    @dewanandkumar8589 Před 6 měsíci +1

    Understood

  • @adityarajvermaa
    @adityarajvermaa Před rokem +6

    i coded the first part by myself fully,,,,,but the second part i could not get the logic of storing in variables at first........but then i get the logic

  • @crazybro4383
    @crazybro4383 Před 5 měsíci

    class Solution {
    public:
    double findMedianSortedArrays(vector& nums1, vector& nums2) {
    int n2 = nums2.size();
    int n1 = nums1.size();
    if(n2 2
    int mid2 = left - mid1;
    int l1 = INT_MIN;
    int l2 = INT_MIN;
    int r1 = INT_MAX;
    int r2 = INT_MAX;
    if(mid1 = 0) l2 = nums2[mid2 - 1];
    if(r1>=l2 && r2>=l1){
    if((n1+n2)%2 != 0){ //odd
    return max(l1, l2);
    }
    else{
    return double(max(l1, l2) + min(r1, r2))/2.0;
    }
    }
    else if(l1 > r2){
    high = mid1-1;
    }
    else{
    low = mid1+1;
    }
    }
    return -1;
    }
    }; This is throwing tle, can someone explain the reason and correct the code

  • @khanra17
    @khanra17 Před 8 měsíci +2

    How is this binary search ?
    I could have solved it, its very simple linear process. But because its inside binary search i stuck finding Binary Search approach.

    • @theonlyarjun
      @theonlyarjun Před 7 měsíci

      same :/

    • @theonlyarjun
      @theonlyarjun Před 7 měsíci +4

      My bad the optimal approach is using BS, it's a separate video :(

  • @Learnprogramming-q7f
    @Learnprogramming-q7f Před 8 měsíci +1

    Thank you Bhaiya

  • @rajatshukla2605
    @rajatshukla2605 Před 3 dny

    Understood!

  • @petersooley3362
    @petersooley3362 Před 10 měsíci +1

    "here comes the twist"

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

    Beautiful

  • @YourCodeVerse
    @YourCodeVerse Před 9 měsíci +1

    Understood✅🔥🔥

  • @NazeerBashaShaik
    @NazeerBashaShaik Před 5 měsíci

    Understood, thank you.

  • @omkarshendge5438
    @omkarshendge5438 Před 3 měsíci

    i did not understand the count method for looking index 1 and index 2, untill then it was fine but then what are looking for like how index 1 will be that element only ??

    • @vaishnavejp9247
      @vaishnavejp9247 Před 3 měsíci

      you can actually break once you found both ind1 and ind2 elements. im not sure why he didnt do it.
      index1 will be that element only because count will only get incremented after you find it. you will ONLY reach index1 count once and only once.

  • @shivamgupta-yz6pc
    @shivamgupta-yz6pc Před 11 měsíci +2

    its still giving partially accepted

  • @per.seus._
    @per.seus._ Před rokem +1

    UNDERSTOOD

  • @DeepakPatel-d5v
    @DeepakPatel-d5v Před 5 měsíci

    Thanks a lot Bhaiya

  • @shaikimran3780
    @shaikimran3780 Před 21 dnem

    Do the code using O(1) space

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

    understood!

  • @akshatpandey2256
    @akshatpandey2256 Před rokem +2

    where was binary search in this problem striver?

  • @stable577
    @stable577 Před 3 měsíci

    how to make notes of these lectures?

  • @abhinanda7049
    @abhinanda7049 Před rokem +1

    understood

  • @karansunilkumbhar2114
    @karansunilkumbhar2114 Před 4 měsíci

    what is time complexity of this solution ?,is it O(m+n) ? if yes then how to solve this in O(log(m)+log(n))?

  • @v1dhn
    @v1dhn Před 4 měsíci

    If someone is looking for a less redundant code:
    class Solution:
    def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
    n1,n2 = len(nums1),len(nums2)
    n = n1+n2
    ind1,ind2 = n//2-1,n//2
    count = 0
    i,j = 0,0
    while i

  • @arpitbhavsar6020
    @arpitbhavsar6020 Před rokem +1

    Understood

  • @sahilkumar1521
    @sahilkumar1521 Před rokem +1

    update this video link on website

  • @SYCOA12CHAITANYAASOLE
    @SYCOA12CHAITANYAASOLE Před 4 měsíci

    Understood !! 😎😎

  • @Shivi32590
    @Shivi32590 Před 2 měsíci

    understood

  • @Mahanth.
    @Mahanth. Před 3 měsíci

    fun fact in better approach : cnt is nothing but i + j

  • @shubhrajit2117
    @shubhrajit2117 Před 3 měsíci

    At 2:16 I thought I'd have to discard the common element 🤦🏻‍♂

  • @sidharthsharma341
    @sidharthsharma341 Před rokem

    Bhaiya which topic will come next ?.....what are upcoming plans

  • @pushkarsingh2162
    @pushkarsingh2162 Před 21 dnem

    Bhai sahi mein tera questions ⁉️😅saarein galat hai 😅

  • @NitaiGauranga-ss8gp
    @NitaiGauranga-ss8gp Před 4 měsíci

    Understand ❤🎉

  • @puneetgared
    @puneetgared Před rokem

    @striver Why not put the OR condition in while loop instead of running while loop separately while merging the array? like
    while(i< arr1.length || j < arr2.length){

  • @VikasSharma-eg8mc
    @VikasSharma-eg8mc Před rokem +1

    🔥🔥🔥🔥🔥

  • @girikgarg8
    @girikgarg8 Před rokem

    Done

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před rokem +1

    Public class solution {
    Public static double median (int []a,int []b){
    int m=a.length, n=b.length;
    int i=0,j=0 m1=0,m2=0;
    for(int count =0;count b[j]){
    m1=b[j++];
    }else {
    m1=a[i++];
    }
    }
    elseif(i

  • @AdityaRoy-p4i
    @AdityaRoy-p4i Před rokem

    Yay🤩

  • @Algorithmswithsubham
    @Algorithmswithsubham Před rokem +1

    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤

  • @farazahmed7
    @farazahmed7 Před rokem

    No BS

  • @pushkarsingh2162
    @pushkarsingh2162 Před 22 dny

    Bhai question to durr ki baat hai English thodi control mein kar 😢

  • @abhinavabhi3568
    @abhinavabhi3568 Před 12 dny

    Understood

  • @MJBZG
    @MJBZG Před 3 měsíci

    understood

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

    Understood

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx Před 8 měsíci

    Understood

  • @abhishekprasad010
    @abhishekprasad010 Před 6 měsíci

    Understood

  • @SibiRanganathL
    @SibiRanganathL Před 6 měsíci

    Understood

  • @hardikpatel352
    @hardikpatel352 Před 5 měsíci

    understood

  • @chiragbansod8252
    @chiragbansod8252 Před 7 měsíci

    understood

  • @firebout7675
    @firebout7675 Před 9 měsíci

    understood