Median of Row Wise Sorted Matrix | Nested Binary Search

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

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

  • @takeUforward
    @takeUforward  3 года назад +13

    Follow me at Instagram: instagram.com/striver_79/​
    Join our telegram group: t.me/Competitive_Programming_tuf

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

      Please explain the break point. Why are we returning low? In normal BS we find mid and return mid. What if 6 was not there in the matrix

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

      @@codeblooded6760 if 6 is not there in the matrix we wont get 6 as the answer suppose we replace all 6 by 7 then for then we will get >4 but for 6 we will get

  • @parthabbot9243
    @parthabbot9243 3 года назад +176

    Apologies but i did not like the way you explained this , you made it quite complex whereas the algorithm is easy to understand but i thank you for giving us this information.

    • @saunaknandi1814
      @saunaknandi1814 3 года назад

      so can u explain this in a simpler way?

    • @atuldwivedi7677
      @atuldwivedi7677 3 года назад +59

      Bhai sahi me explanation bouncer jaa rha hai ek dum

    • @mayur_madhwani03
      @mayur_madhwani03 2 года назад +16

      Totally agreed

    • @hritikmanbattulwar
      @hritikmanbattulwar 2 года назад

      ruclips.net/video/Ul8zBtVFXOo/видео.html watch this and comeback here. you will understand it for sure

    • @golugu3145
      @golugu3145 Год назад +10

      very poorly explained couldn't understand anything.

  • @ravishankardas4856
    @ravishankardas4856 2 года назад +53

    for finding the mid one should use low+(high-low)/2 as when using high+low/2 the high+low can overflow

  • @KeshariPiyush24
    @KeshariPiyush24 2 года назад +61

    A JAVA Solution with some questions answered whic might confuse some people(me as well).
    *Q1) Why r and c are always odd?*
    If r and c both are odd then this means that number of elements int the matrix will also be odd which is actually necessary for binary search to be applicable here(only in this problem, binary serach works for both even and odd elements arrays when the array is linear but not here). Because here we are judging by considering the fact that no of elements less than or equal to current number, which in case of even no of elements can be a number which is not present in the matrix. Having odd number of elements has a property that the middle element is cleary defined (a single mid) so number of elements to the left of it and right of it will be equal but in case of even population we can sometime have a median element which is
    not present in the array which will not be possible to find in case of a matrix like this without traversing all the elements.
    This method will give wrong result for even number of elements so let's not worry about it.
    *Q2 ) Why half = (r * c) / 2 and not (r * c + 1) / 2 as no of elements are odd and we know middle for odd is (n + 1) / 2 ?*
    To this I will reply that the condition *if (cnt

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

      because this algo works only on odd length array

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

      @Piyush kesari,
      You are wrong for the "Q1".
      If case of even number of elements, if you follow this algorithm, you will DEFINITELY get an element from the matrix for sure. BUT THIS IS NOT OBVIOUSLY THE MEDIAN.
      IF possible show an conuter example to my statement

  • @satvrii
    @satvrii Год назад +9

    For so long I avoided this question just because the comments were negative, I finally saw and realised that it's perfect explanation as always ❤❤❤❤❤❤❤

  • @sahilsonkar9979
    @sahilsonkar9979 3 года назад +118

    first time,it's very confusing explanation

  • @sahilgupta9378
    @sahilgupta9378 3 года назад +10

    Thanks for the explanation I had to watch multiple times(2-3). Actually the confusion is that it was not clearly mentioned that we were looking for
    count(mid)

  • @deepali-e6f
    @deepali-e6f 2 года назад +10

    What I have figured out after 3 hours is that :
    1 ) Why we are taking no of elements

    • @utkarshraj5475
      @utkarshraj5475 2 года назад

      Thanks 😊

    • @DeepSingh-zs2oi
      @DeepSingh-zs2oi 2 года назад

      These two points were really helpful!! Second point also proves why low is definitely present in the matrix. We had to find element such that no. of ele

    • @aabhassao
      @aabhassao 2 года назад

      thanks

  • @Mr_SSK
    @Mr_SSK 2 года назад +8

    The search space can be reduced by setting 'high=maxEle(matrix)', and the 'maxEle()' can work in O(noOfRows) as we'll compare the last element only for every row (because the rows are sorted)
    Thank You sooooo much for such easy explanations!💜

    • @vishalgupta957
      @vishalgupta957 2 года назад +2

      but in case of 1e9 it runs only for 32 times, still better if no.of rows=500.

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

      @@vishalgupta957 either way order of time complexity would remain the same i.e nlogM

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

      @@sanidhyatahiliani6797 ummm its better if we write M + n logM because there may be a case where say M = 399 , n = 3 => O(399) + O(3*log(399))

  • @jitesh.khuttan
    @jitesh.khuttan 3 года назад +11

    How is "low" always converging to an element within a matrix? This is something I am not able to understand.

    • @takeUforward
      @takeUforward  3 года назад +1

      Since nai ho rha th right ya left move kr rhe. So ek samay aayega ek banda toh hoga

    • @RahulYadav-nl1ek
      @RahulYadav-nl1ek 3 года назад +2

      yes,,, same why is it so that low always converges to answer?

    • @RahulYadav-nl1ek
      @RahulYadav-nl1ek 3 года назад +4

      please clarify striver
      the video solution is not very clear and it says nothing about the core logic of the solution

    • @takeUforward
      @takeUforward  3 года назад +3

      I have mentioned this in other comments, do a dry run with other set of examples to understand more..

    • @ashishsingh-ty6kf
      @ashishsingh-ty6kf 3 года назад +1

      yes there is a possibility that our number might not be present the matrix that us why we aree doing mid +1 to check for more numbers and reducing search space in the end we are bound to meet a number which have cnt as

  • @imranwahid9871
    @imranwahid9871 3 года назад +11

    Why are you taking the high point of binary search as 1e9?? You could have taken the high point as the maximum element of the matrix . In that fashion you could have reduced the search space.

    • @pratyushnarain5220
      @pratyushnarain5220 3 года назад +1

      nice optimization bro and we should take the min as minimum of the matrix

    • @The_Promised_Neverland...
      @The_Promised_Neverland... 3 года назад +1

      Bro, that's not a good practice tbh...you're just trying to put load for finding the max and min....I know it'll hardly matter but think for very large test cases for example a matrix of size 1e5 * 1e5 , hope you understand

    • @adityamahimkar6138
      @adityamahimkar6138 3 года назад

      In that case the TC for finding max of a matrix is equivalent to the naive approach and it's better to go with that.

    • @pratyushnarain5220
      @pratyushnarain5220 3 года назад +3

      @@adityamahimkar6138 no the TC of finding max is O(rows) bcoz the matrix is sorted row wise

    • @SoloScholar0202
      @SoloScholar0202 3 года назад +1

      @@pratyushnarain5220 agree since the minimum element would be present in the first column and the maximum element would be present in the last column.

  • @ramanshusingh7619
    @ramanshusingh7619 3 года назад +2

    You made time complexity O(nlogn) while doing the loop twice, once outside the equaltomid function and one inside it. The compiler will disregard saying time limit exceeded

    • @sameemsheikh2914
      @sameemsheikh2914 3 года назад +7

      The outer loop will run for 32 time at max, the inner loop will always run for N times and the function will run for log(N). So the worst case can go upto 32*N*log(M). It shouldn't give us tle

    • @insane2539
      @insane2539 2 года назад

      @@sameemsheikh2914 how outer loop will run max 32 times?

    • @siddharthchabukswar2
      @siddharthchabukswar2 2 года назад +4

      @@insane2539 As the INT_MAX here is 2^32, and we are dividing the search space in (log(n) == log(2^32)) times which is 32.

  • @AshutoshPandey-se8vt
    @AshutoshPandey-se8vt 2 года назад +9

    Q::But I am still confused a bit. My Query is, low and high are taken as 1 and 1e9 which are not necessarily in our matrix. And then after we do mid = (low+high)/2, and again we are uncertain whether mid even lies in the matrix or not, and we keep doing it until we come to a favourable situation, and that uncertainty still prevails , but how does this guarantees that whatever 'low' was last calculated actually lies in the matrix???
    I mean its just an avg of two numbers!
    ANS: Since N*M is always odd we can never get a number that is not in the matrix and still half of the no's are greater than it and half of them is less than that number.

    • @realWorldDevStudio
      @realWorldDevStudio 2 года назад +6

      This statement can be better understood if you write on paper and check by yourself .
      m x n = total number of elements .
      Case 1 : m x n is even
      E . g [ 1 , 32 , 56 , 67 ]
      Observation : 34 can be a median but not in array , also 33 , 35 ,36 .... 55 can be median although they are not in array .
      Case 2: m x n is odd
      E.g [ 1 , 32 , 56 , 67 , 89 ]
      Can you tell any number which can be not in array but still can be median ( a number which is greater than half of the elements and smaller than half of elements )
      The ans is you can't .
      There can be only median which is 56 .
      In order for an element to a median which is not in array it has to be greater than half elements say n1 and other smaller than other half n2 . since n1 and n2 are equal their sum should be even but the array is odd length .
      It is given than m * n == total elements in array is odd

    • @Anonymous-pj2mv
      @Anonymous-pj2mv 2 года назад

      @@realWorldDevStudio What about 33, 34, 66, etc.

    • @realWorldDevStudio
      @realWorldDevStudio 2 года назад

      @@Anonymous-pj2mv I just gave same examples all the numbers between can be if total elements are even

    • @Anonymous-pj2mv
      @Anonymous-pj2mv 2 года назад

      @@realWorldDevStudio okay, Now I got it. Thanks.

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

      @@realWorldDevStudio but how can we conclude that low is the median?

  • @sushantsingh5689
    @sushantsingh5689 3 года назад +9

    Median should always be an element from the matrix. How do we assure, lo=mid+1 or hi will be an element from the matrix? As It has possible the middle value is something not present in the matrix .

    • @takeUforward
      @takeUforward  3 года назад +3

      Take some examples, or read other comments. I have answered this..

    • @3amvibes443
      @3amvibes443 2 года назад +1

      @@takeUforward use upper_bound function?

  • @AshutoshPandey-se8vt
    @AshutoshPandey-se8vt 2 года назад +5

    ANS: Since N*M is always odd we can never get a number that is not in the matrix and still half of the no's are greater than it and half of them is less than that number.

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

      I was having this doubt but can you please elaborate this. Thank You.

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

      If case of even number of elements, if you follow this algorithm, you will DEFINITELY get an element from the matrix for sure. BUT THIS IS NOT OBVIOUSLY THE MEDIAN.

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

    If someone comes up with this solution in an interview, hats off to them!

  • @AkshayKumar-xh2ob
    @AkshayKumar-xh2ob 3 года назад +5

    This is not just a video about the problem but also about Binary Search intuition.

  • @adityaraj5200
    @adityaraj5200 3 года назад +12

    But I am still confused a bit. My Query is, low and high are taken as 1 and 1e9 which are not necessarily in our matrix. And then after we do mid = (low+high)/2, and again we are uncertain whether mid even lies in the matrix or not, and we keep doing it until we come to a favourable situation, and that uncertainty still prevails , but how does this guarantees that whatever 'low' was last calculated actually lies in the matrix???
    I mean its just an avg of two numbers!

    • @takeUforward
      @takeUforward  3 года назад +5

      Thats why we keep moving till we dont reach to a number where this breaks.. hence low > high is the break point.
      When I get confused in this way, I generally take some more examples and a smaller search space and try to do binary search. Only you can increase your understanding by doing self dry runs :) try this method and then ping here if still problem

    • @adityaraj5200
      @adityaraj5200 3 года назад +1

      @@takeUforward Okay thanks. i got it after dry running and observing some random set of testcases of my own .

    • @kurubakirankumar9112
      @kurubakirankumar9112 3 года назад +2

      @@adityaraj5200 Bro ,I also have the same doubt which was raised by you. I tried this algo. on multiple test cases, the ans coming is right but I still can't understand that whatever 'low' was last calculated actually lies in the matrix?

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 года назад

      search space can be minimum and max number of the matrix.

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 года назад

      @@takeUforward search space can be minimum and max number of the matrix.

  • @anshumansharma4580
    @anshumansharma4580 3 года назад +2

    Please tell me what I am doing wrong?
    Let us take the test case : [1,2,3,4,5]
    Let us say initially my low and high are 1 and 7.
    So mid= 4, I counted number of elements less than equal to 4 as 4.
    So I see that a median can have this value but let us try to shrink the value, so I move left.
    New low=1,
    high= 3,
    mid=2,smaller equal to- 2
    This can't be the median so we move right
    low=3 hi=4
    mid=3
    elements less than equal to 3 are 3,
    which is less so again move right
    low=4 high=4
    med=4
    elements less than equal to 4 which are more so we move left
    low =4, high=3 we break
    Now median comes out to be 4 but actually it is 3,
    Please tell my mistake.

    • @takeUforward
      @takeUforward  3 года назад

      Use print line to understand..

    • @shubhamagarwal9321
      @shubhamagarwal9321 3 года назад +4

      In the 3rd step you changed the value of high also(from 3 to 4)....

  • @krishan7976
    @krishan7976 2 года назад +2

    shouldn't the median also be the mean of two middle elements in the case of even numbers?

    • @abhishekpilla8857
      @abhishekpilla8857 2 года назад +2

      In the question it was made sure n*m is always odd

  • @rohitkumar-lj2ru
    @rohitkumar-lj2ru 3 года назад +7

    I believe , you can add another solution using priority_queue (max heap) of size k = (r*c+1)/2.

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

      in qn. they asked for size complexity O(1)

  • @guningupta2745
    @guningupta2745 2 года назад +1

    Why have we taken the search space from 1 and not 0?
    Is it mentioned anywhere that 0 will not be the element inside the array?

    • @ajaykmr8684
      @ajaykmr8684 2 года назад

      Yes, in the constraints it is mentioned.

  • @preetijavali6595
    @preetijavali6595 20 дней назад

    In this we are not finding the mid by index but by the value ?

  • @KD-xi9wu
    @KD-xi9wu 3 года назад +3

    7:28 but isn't that seven numbers excluding eight?????

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

    one small condition can be added in for loop to optimize the code by skipping unwanted binary search for each for. We can just check the last element of each row with mid and last element is greater than or equal to mid than we can just add number of columns to cnt
    Here is the code:
    for(int i=0;i=matrix[i].back()){
    cnt+=m;
    }
    else{
    cnt+=countSmallerThanEqualTo(matrix[i],mid);
    }
    }

  • @amrithapatil4595
    @amrithapatil4595 2 года назад +2

    how can you be sure that low would be a part of the matrix?

    • @shivamnegi7552
      @shivamnegi7552 2 года назад +1

      If you have an array and it is sorted , and you have to find median , then the number of elements lesser or equal to median will be equal to number of elements greater or equal to median .. okay ??? so this is the basic intuition to do binary search .. we are dividing the array until there's a breakdown ..we are not searchingg the element here , do you get this ?? *WE ARE NOT SEARCHING , THATS WHY WE WILL DON'T FIND SOMETHING THATS NOT PRESENT ,WE ARE HAVING A BREAKPOINT * get it ? if we come to an elements that is not present and has equal number of elements both the sides , we will trim our array ..and this trimming will lead us to a breakpoint where we will reach our answer.

  • @willturner3440
    @willturner3440 3 года назад +5

    One of the hard problm in binary search

  • @saunaknandi1814
    @saunaknandi1814 3 года назад +1

    is not the code a little different from what u explained?

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

    bhaiyya at 7:31 how come there are 7 nos.

  • @gauravgupta5530
    @gauravgupta5530 2 года назад +6

    I think you made this very complex while teaching. Its very difficult to understand while watching this video

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

    Can the concept used in "Median of Two Sorted Arrays" be leveraged here?

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

    if (cnt

  • @botsbucketlist9515
    @botsbucketlist9515 2 года назад +4

    yeah didnt get it
    striver

  • @shreyasingh1258
    @shreyasingh1258 3 года назад +13

    Explanation op!🔥 Thanks a lot striver

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

    How are we sure that low is present in the matrix?

  • @ankitdubey9310
    @ankitdubey9310 3 года назад +4

    low + high >> l ??
    what does this mean?

  • @divyamalik7484
    @divyamalik7484 2 года назад

    Can you please let me know why this program giving me runtime error?
    int row=matrix.size();
    int col=matrix[0].size();
    vector arr(row*col);

    for(int i=0;i

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

      for(int j=0;i

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

      it should be vector arr; , don't specify the size because vector arr(row*col) will create vector with '0', and further insertion will take place after it.. i think thats why its not working

  • @csedatasceince-a6886
    @csedatasceince-a6886 6 месяцев назад

    what is the answer we get is not there in the matrix

  • @shivambajpeyi9008
    @shivambajpeyi9008 3 года назад +1

    watched it several times, finally understooood bhaiyya!!

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

    just amazing expaination i learn a new concept of takinf a element from the range and solve 2 questions more🤩☺☺☺

  • @Nishant89-i2z
    @Nishant89-i2z 3 года назад +9

    Aagya naya video aagya fir placement hi placement hoga

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

    guys if u don't understand at some point look at the code and again watch this video , you will definetly understand :))

  • @eshanchourasia287
    @eshanchourasia287 3 года назад +1

    Bhaiya there is one mistake in your code ig ,like you have written if the no of count is

  • @ayushagrawal1103
    @ayushagrawal1103 3 года назад +3

    Bhai I am like kehna kya chahte ho 🙄..
    Really didn't get a bit of it 🥺🥺

  • @NithishKumar-hx8do
    @NithishKumar-hx8do 3 года назад +3

    Why are we using the condition

    • @ferozmohammad5841
      @ferozmohammad5841 3 года назад +1

      because bro, we have to count the numbers less than or equal to itself. For example, in [1, 2, 3, 4, 5], if you find numbers less than 3, you find only 2 numbers. If you consider only less than 3 here, it wouldn't practically give you answer . It would be easy to pick median from the odd number of elements, the question has stated the same that the array has odd number of elements.

    • @SoloScholar0202
      @SoloScholar0202 3 года назад +1

      we take

  • @anikettibrewal3608
    @anikettibrewal3608 3 года назад +1

    can't we go with two functions:
    cnt1+= countSmallerThan(a[i],mid)
    cnt2+= countSmallerThanEqualTo(a[i],mid)
    mid_ind = (n+m)/2
    if(mid_ind > cnt1 && mid_ind

  • @GauravKumar-dw2ml
    @GauravKumar-dw2ml 2 года назад

    what if 7 was there instead of 6 then 5+1=6 would be wrong ? #Doubt

  • @_-6912
    @_-6912 3 года назад +3

    Its confusing for me,

  • @tejas7379
    @tejas7379 3 года назад

    code gave error in the problem link :)
    Any help!!

  • @Yash-uk8ib
    @Yash-uk8ib 3 года назад +5

    can anyone tell me whether the search space be b/w 1 to max-element of the given matrix? Also, what is the intuition behind taking such a large search space?

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 года назад +4

      search space can be the minimum and max number of the matrix.

    • @Yash-uk8ib
      @Yash-uk8ib 3 года назад +1

      @@SudhanshuKumar-lp1nr thanks sir

    • @Yash-uk8ib
      @Yash-uk8ib 3 года назад

      @@SudhanshuKumar-lp1nr can u tell me the intuition behind taking this large search space?

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 3 года назад

      my search space was smaller than the search space used in the video, so I decided to take a smaller search space

    • @Kaivalyamani
      @Kaivalyamani 3 года назад

      I have tried using the smaller search space between - min and max of matrix but on gfg it passes some test case while it gives segment ation error on some. I dont know why

  • @divyanshuupadhyay9831
    @divyanshuupadhyay9831 2 года назад +2

    nhi aya smjh
    krna hi kyu h optimize🙂🤧🤧😭😭😭

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

    Sheer beauty in explanation!! thankyou so much!!

  • @etherealgaming7328
    @etherealgaming7328 2 года назад +6

    Guys low

    • @_inspireverse___
      @_inspireverse___ 2 года назад

      please bro share the link
      really i need that video.

    • @santhoskumar1369
      @santhoskumar1369 2 года назад

      @@_inspireverse___ ruclips.net/video/LcWPKR1uef4/видео.html

  • @ishaansalwan4017
    @ishaansalwan4017 3 года назад +1

    I had a doubt , for the sub problem of finding the index just greater than a given value , can we find the last occurrence of that element and then last occurence - 0 will give the elements lesser than and equal to the given value?

    • @sameemsheikh2914
      @sameemsheikh2914 3 года назад

      it is much trickier to find the last occurrence of an element than finding an element just greater than itself

  • @rishikantpatel5008
    @rishikantpatel5008 2 года назад

    Confusion in low ends with median?

  • @gamingblast2325
    @gamingblast2325 3 года назад +5

    Thanks for such a great explanation !!

  • @editorera239
    @editorera239 3 года назад +3

    10:48 m smgh ni aya bro

  • @harshitvarshney2627
    @harshitvarshney2627 3 года назад +2

    Bhaiya....plz make a separate playlist on tree

  • @virendrashekhawat7198
    @virendrashekhawat7198 3 года назад +4

    Bro one thing, in explanation you are referring median position as 5 which is (n*m+1)/2 and in code you are comparing with
    (n*m)/2

  • @niitteenpathak8303
    @niitteenpathak8303 2 года назад +1

    Samajh ni aya par sun kar acha laga😄

  • @MJ-dq8om
    @MJ-dq8om 3 года назад +1

    What is meant by monotonic increasing?

    • @shreyasaxena5169
      @shreyasaxena5169 3 года назад +7

      1*1 = 1
      2*2 = 4
      3*3 = 9
      here for 1 its 1 for 2 its 4 for 3 its 9 and so on.
      1-2-3- >> Increasing
      1-4-9- >> Increasing
      Both are linearly increasing.
      For a bigger number the corresponding result is also bigger then this pattern is monotonically increasing.

  • @roopeshroope5988
    @roopeshroope5988 3 года назад +2

    What does the constraint 1 to 10^9 mean

    • @takeUforward
      @takeUforward  3 года назад

      Open the question link in the description.

    • @manvikarya725
      @manvikarya725 3 года назад +1

      We can even set the low = min value in matrix, high = max value in matrix

    • @takeUforward
      @takeUforward  3 года назад +3

      @@manvikarya725 in order to find that we will waste time.

    • @sauravkumargupta2594
      @sauravkumargupta2594 3 года назад +2

      @@takeUforward It will take only O(n) time, to find min and max, because 0th and (m-1)th index of row will contain these values, then it will not exceed time

    • @takeUforward
      @takeUforward  3 года назад +2

      @@sauravkumargupta2594 why do you want to use some extra time 👀

  • @avinav6687
    @avinav6687 2 года назад +4

    I really didn't understand this question to be honest

    • @scorcism.
      @scorcism. Год назад

      same, if you knwo can you help me

  • @vaibhavgcool
    @vaibhavgcool 2 года назад +1

    Isn't this question similar to 'Kth element in a sorted array'? In place of k we just replace it with (size/2)+1 and apply the same approach but it doesn't run for all test cases

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

      Yes : we uses the quickselect algorithm on it, but the matrix is sorted row wise, then it would be better to use the binary search on it...

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

    Thank You So Much Striver Brother......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @navendraagrawal
    @navendraagrawal 2 года назад +1

    this is giving tle in gfg
    wrong code

    • @takeUforward
      @takeUforward  2 года назад +1

      Gfg is wrong, try lc :)

    • @premmane9816
      @premmane9816 2 года назад

      @@takeUforward bhaiya its giving wrong output in gfg plz you try and if its really wrong then pin a comment becoz many of them wasted their whole day in seeing what is wrong in this code like me.

  • @shivangisrivastava1158
    @shivangisrivastava1158 2 года назад +1

    Great video as always, totally love your voice.

  • @ADNANAHMED-eo5xx
    @ADNANAHMED-eo5xx 3 года назад +3

    Thanks Striver 79 !!!

  • @pappu_bakait
    @pappu_bakait 2 года назад

    Please make a video on "Kth smallest element in a row and column wise sorted matrix" using Binary Search.

  • @koriviramnath1631
    @koriviramnath1631 3 года назад

    int md = (l+h) >> 1 what exactly this line of code do plz help i know ">>" this is a shifting operator

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

    Awesome explanation. Thanks for the amazing video.

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

    Very good explanation mind blowing

  • @KrishnaSingh-je8pu
    @KrishnaSingh-je8pu Год назад

    any one can explain me why we used mid = (low + high) >> 1 rather then mid=(low+high)/2

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

      (low + high) >> 1 means left shift low+high by 1 bit , which is nothing but (low+high)/2

  • @dipesh1401
    @dipesh1401 2 года назад

    what if the mid element is not in 2d matrix?

    • @shivamnegi7552
      @shivamnegi7552 2 года назад

      If you have an array and it is sorted , and you have to find median , then the number of elements lesser or equal to median will be equal to number of elements greater or equal to median .. okay ??? so this is the basic intuition to do binary search .. we are dividing the array until there's a breakdown ..we are not searchingg the element here , do you get this ?? *WE ARE NOT SEARCHING , THATS WHY WE WILL DON'T FIND SOMETHING THATS NOT PRESENT ,WE ARE HAVING A BREAKPOINT * get it ? if we come to an elements that is not present and has equal number of elements both the sides , we will trim our array ..and this trimming will lead us to a breakpoint where we will reach our answer.

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

    couldn't understand anything

  • @sameergupta150
    @sameergupta150 3 года назад +2

    Excellent explanation

  • @paragroy5359
    @paragroy5359 3 года назад

    Nice explanation your videos are really good...please keep on making such videos.

  • @jatilyadav4000
    @jatilyadav4000 2 года назад

    thank you soo much for this kind of video which cleared my concept

  • @prathamjagga5597
    @prathamjagga5597 3 года назад +2

    Bro how to find maximum subarray sum which is even

  • @sumitpd572
    @sumitpd572 2 года назад

    anyone why the search space is 10^9?

  • @darkamv-x5822
    @darkamv-x5822 2 года назад

    U are great explainer on u tube

  • @raj_kundalia
    @raj_kundalia 2 года назад

    Thanks you for the wonderful explanation.

  • @gautam4696
    @gautam4696 3 года назад +2

    bhai tum bohot acha padhate ho par agar hindi main padhao toh zyada acha , varna kuch samagh nahi aa raha jo tum bol rahe ho.

  • @arushimathur7205
    @arushimathur7205 3 года назад +2

    Explanation is good , but don't take coding ninjas. Its a big waste of money.

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

    not clear :(
    please rerecord this video

  • @kshitijsharma2121
    @kshitijsharma2121 2 года назад +3

    This is a very confusing explanation. Please consider replacing this tutorial with a new understandable one

  • @saichennu5288
    @saichennu5288 3 года назад +1

    Bro please solve reorder data in log files leetcode problem

  • @atifhu
    @atifhu 2 года назад +1

    Python walo se iss sajjan ko kya taqleef hai bhai😂

  • @tanmaymishra1109
    @tanmaymishra1109 2 года назад +1

    Like other comments,it is very confusing

  • @AyushKumar-ju9jj
    @AyushKumar-ju9jj 2 года назад +1

    Bhai hgg diya tune is explaination me

  • @kaustav07
    @kaustav07 3 года назад

    Please upload solution for AtCoder DP contest knapsack 2 problem. Please.

  • @ayushjain7748
    @ayushjain7748 2 года назад +2

    You confused all of us buddy.

  • @pujakumari6391
    @pujakumari6391 2 года назад

    Samjh nhi aaya..🥲

  • @funenjoynilaypatel4553
    @funenjoynilaypatel4553 2 года назад +1

    9 march 2022 11:06 pm

  • @stevejob677
    @stevejob677 3 года назад +2

    sir please make a vedio on hindi+English vocab please sir

  • @satyamgupta7608
    @satyamgupta7608 2 года назад

    1:56

  • @laxminarayanchoudhary939
    @laxminarayanchoudhary939 3 года назад

    I can't understand how to thank you Broo..

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

    Understood

  • @dipuprasad9196
    @dipuprasad9196 3 года назад

    Thank you bhaiya very clear to me it is was

  • @bhaveshkumar6842
    @bhaveshkumar6842 2 года назад

    Thank you