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

Поделиться
HTML-код
  • Опубликовано: 17 окт 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...

Комментарии • 74

  • @takeUforward
    @takeUforward  Год назад +12

    Please watch our new video on the same topic: ruclips.net/video/F9c7LpRZWVQ/видео.html

  • @balakrishnanr648
    @balakrishnanr648 Год назад +49

    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 4 месяца назад +11

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

  • @amitranjan6998
    @amitranjan6998 Год назад +29

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

  • @mohit5963
    @mohit5963 Год назад +2

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

  • @cinime
    @cinime Год назад +5

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

  • @pratyushtripathi1728
    @pratyushtripathi1728 11 месяцев назад +7

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

  • @anshsaxena7297
    @anshsaxena7297 Месяц назад

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

  • @khanra17
    @khanra17 8 месяцев назад +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 8 месяцев назад

      same :/

    • @theonlyarjun
      @theonlyarjun 8 месяцев назад +4

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

  • @smrutisitikanta2664
    @smrutisitikanta2664 3 месяца назад

    What a brilliant approach!!!

  • @001_bajpai5
    @001_bajpai5 9 месяцев назад +2

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

  • @adityarajvermaa
    @adityarajvermaa Год назад +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

  • @rupeshpatil6957
    @rupeshpatil6957 22 дня назад

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

  • @stith_pragya
    @stith_pragya 8 месяцев назад +1

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

  • @kaichang8186
    @kaichang8186 8 дней назад

    understood, thanks for the perfect explanation

  • @dineshdsv7815
    @dineshdsv7815 10 месяцев назад +2

    Thanks for the detailed explanation

  • @omkarshendge5438
    @omkarshendge5438 3 месяца назад

    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 3 месяца назад

      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.

  • @akshatpandey2256
    @akshatpandey2256 Год назад +2

    where was binary search in this problem striver?

    • @nikhilkumarjamwal5322
      @nikhilkumarjamwal5322 11 месяцев назад

      Me thinking of that too.
      Ain't this normal array question???

    • @shreyxnsh.14
      @shreyxnsh.14 8 месяцев назад +4

      watch the optimal solution dude

  • @stable577
    @stable577 3 месяца назад

    how to make notes of these lectures?

  • @karansunilkumbhar2114
    @karansunilkumbhar2114 4 месяца назад

    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))?

    • @deepakjain4481
      @deepakjain4481 2 месяца назад +1

      The complexity you are mentioning is logm*n that is not asked

    • @deepakjain4481
      @deepakjain4481 2 месяца назад +1

      It's log(m+n)

  • @crazybro4383
    @crazybro4383 5 месяцев назад

    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

  • @shivamgupta-yz6pc
    @shivamgupta-yz6pc 11 месяцев назад +2

    its still giving partially accepted

  • @shaikimran3780
    @shaikimran3780 25 дней назад

    Do the code using O(1) space

  • @dewanandkumar8589
    @dewanandkumar8589 6 месяцев назад +1

    Understood

  • @rajatshukla2605
    @rajatshukla2605 7 дней назад

    Understood!

  • @YourCodeVerse
    @YourCodeVerse 9 месяцев назад +1

    Understood✅🔥🔥

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 8 месяцев назад +1

    Thank you Bhaiya

  • @sahilkumar1521
    @sahilkumar1521 Год назад +1

    update this video link on website

  • @Yogamindmastery
    @Yogamindmastery Месяц назад

    Beautiful

  • @NazeerBashaShaik
    @NazeerBashaShaik 6 месяцев назад

    Understood, thank you.

  • @per.seus._
    @per.seus._ Год назад +1

    UNDERSTOOD

  • @sidharthsharma341
    @sidharthsharma341 Год назад

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

  • @DeepakPatel-d5v
    @DeepakPatel-d5v 5 месяцев назад

    Thanks a lot Bhaiya

  • @sanketatmaram
    @sanketatmaram Месяц назад

    understood!

  • @petersooley3362
    @petersooley3362 10 месяцев назад +1

    "here comes the twist"

  • @SYCOA12CHAITANYAASOLE
    @SYCOA12CHAITANYAASOLE 4 месяца назад

    Understood !! 😎😎

  • @arpitbhavsar6020
    @arpitbhavsar6020 Год назад +1

    Understood

  • @abhinanda7049
    @abhinanda7049 Год назад +1

    understood

  • @pushkarsingh2162
    @pushkarsingh2162 24 дня назад

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

  • @puneetgared
    @puneetgared Год назад

    @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){

  • @Shivi32590
    @Shivi32590 2 месяца назад

    understood

  • @NitaiGauranga-ss8gp
    @NitaiGauranga-ss8gp 4 месяца назад

    Understand ❤🎉

  • @Mahanth.
    @Mahanth. 3 месяца назад

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

  • @VikasSharma-eg8mc
    @VikasSharma-eg8mc Год назад +1

    🔥🔥🔥🔥🔥

  • @girikgarg8
    @girikgarg8 Год назад

    Done

  • @shubhrajit2117
    @shubhrajit2117 3 месяца назад

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

  • @v1dhn
    @v1dhn 4 месяца назад

    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

  • @AdityaRoy-p4i
    @AdityaRoy-p4i Год назад

    Yay🤩

  • @Algorithmswithsubham
    @Algorithmswithsubham Год назад +1

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

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Год назад +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

  • @pushkarsingh2162
    @pushkarsingh2162 25 дней назад

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

  • @farazahmed7
    @farazahmed7 Год назад

    No BS

  • @SitaRam-m1i
    @SitaRam-m1i День назад

    Understood

  • @MJBZG
    @MJBZG 3 месяца назад

    understood

  • @abhinavabhi3568
    @abhinavabhi3568 16 дней назад

    Understood

  • @codeman3828
    @codeman3828 Месяц назад

    Understood

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx 8 месяцев назад

    Understood

  • @abhishekprasad010
    @abhishekprasad010 6 месяцев назад

    Understood

  • @SibiRanganathL
    @SibiRanganathL 6 месяцев назад

    Understood

  • @hardikpatel352
    @hardikpatel352 5 месяцев назад

    understood

  • @chiragbansod8252
    @chiragbansod8252 7 месяцев назад

    understood

  • @firebout7675
    @firebout7675 9 месяцев назад

    understood