Median of Row Wise Sorted Matrix | Nested Binary Search

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 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 ปีที่แล้ว +178

    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 ปีที่แล้ว

      th-cam.com/video/Ul8zBtVFXOo/w-d-xo.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 ปีที่แล้ว +54

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

  • @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 ปีที่แล้ว +119

    first time,it's very confusing explanation

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

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

  • @Mr_SSK
    @Mr_SSK 2 ปีที่แล้ว +9

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

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

  • @AkshayKumar-xh2ob
    @AkshayKumar-xh2ob 3 ปีที่แล้ว +5

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

  • @abhicasm9237
    @abhicasm9237 ปีที่แล้ว

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

  • @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);
    }
    }

  • @willturner3440
    @willturner3440 3 ปีที่แล้ว +5

    One of the hard problm in binary search

  • @Nishant89-i2z
    @Nishant89-i2z 3 ปีที่แล้ว +9

    Aagya naya video aagya fir placement hi placement hoga

  • @shreyasingh1258
    @shreyasingh1258 3 ปีที่แล้ว +13

    Explanation op!🔥 Thanks a lot striver

  • @gauravgupta5530
    @gauravgupta5530 2 ปีที่แล้ว +6

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

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

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

  • @botsbucketlist9515
    @botsbucketlist9515 2 ปีที่แล้ว +4

    yeah didnt get it
    striver

  • @shivambajpeyi9008
    @shivambajpeyi9008 3 ปีที่แล้ว +1

    watched it several times, finally understooood bhaiyya!!

  • @etherealgaming7328
    @etherealgaming7328 2 ปีที่แล้ว +6

    Guys low

    • @_inspireverse___
      @_inspireverse___ 2 ปีที่แล้ว

      please bro share the link
      really i need that video.

    • @santhoskumar1369
      @santhoskumar1369 2 ปีที่แล้ว

      @@_inspireverse___ th-cam.com/video/LcWPKR1uef4/w-d-xo.html

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

  • @piyushkhandelwal1662
    @piyushkhandelwal1662 ปีที่แล้ว

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

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

  • @niitteenpathak8303
    @niitteenpathak8303 2 ปีที่แล้ว +1

    Samajh ni aya par sun kar acha laga😄

  • @kshitijsharma2121
    @kshitijsharma2121 2 ปีที่แล้ว +3

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

  • @RandomBoy_0o0
    @RandomBoy_0o0 ปีที่แล้ว

    Sheer beauty in explanation!! thankyou so much!!

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

  • @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 ปีที่แล้ว +2

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

  • @gamingblast2325
    @gamingblast2325 3 ปีที่แล้ว +5

    Thanks for such a great explanation !!

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

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

  • @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 :))

  • @avinav6687
    @avinav6687 3 ปีที่แล้ว +4

    I really didn't understand this question to be honest

    • @scorcism.
      @scorcism. ปีที่แล้ว

      same, if you knwo can you help me

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

  • @ADNANAHMED-eo5xx
    @ADNANAHMED-eo5xx 3 ปีที่แล้ว +3

    Thanks Striver 79 !!!

  • @shivangisrivastava1158
    @shivangisrivastava1158 2 ปีที่แล้ว +1

    Great video as always, totally love your voice.

  • @KD-xi9wu
    @KD-xi9wu 3 ปีที่แล้ว +3

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

  • @preetijavali6595
    @preetijavali6595 หลายเดือนก่อน

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

  • @ayushagrawal1103
    @ayushagrawal1103 3 ปีที่แล้ว +3

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

  • @darkamv-x5822
    @darkamv-x5822 2 ปีที่แล้ว

    U are great explainer on u tube

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 ปีที่แล้ว

    Very good explanation mind blowing

  • @arushimathur7205
    @arushimathur7205 3 ปีที่แล้ว +2

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

  • @sameergupta150
    @sameergupta150 3 ปีที่แล้ว +2

    Excellent explanation

  • @golugu3145
    @golugu3145 ปีที่แล้ว +1

    couldn't understand anything

  • @stith_pragya
    @stith_pragya 2 ปีที่แล้ว

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

  • @harshitvarshney2627
    @harshitvarshney2627 3 ปีที่แล้ว +2

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

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

  • @bharatmehta30
    @bharatmehta30 ปีที่แล้ว

    Awesome explanation. Thanks for the amazing video.

  • @ayushjain7748
    @ayushjain7748 2 ปีที่แล้ว +2

    You confused all of us buddy.

  • @_-6912
    @_-6912 3 ปีที่แล้ว +3

    Its confusing for me,

  • @priyankakataria7922
    @priyankakataria7922 ปีที่แล้ว

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

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

  • @arushiagarwal100
    @arushiagarwal100 ปีที่แล้ว

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

  • @jatilyadav4000
    @jatilyadav4000 2 ปีที่แล้ว

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

  • @divyanshuupadhyay9831
    @divyanshuupadhyay9831 2 ปีที่แล้ว +2

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

  • @paragroy5359
    @paragroy5359 3 ปีที่แล้ว

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

  • @saunaknandi1814
    @saunaknandi1814 3 ปีที่แล้ว +1

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

  • @eshanchourasia287
    @eshanchourasia287 3 ปีที่แล้ว +1

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

  • @tanmaymishra1109
    @tanmaymishra1109 2 ปีที่แล้ว +1

    Like other comments,it is very confusing

  • @raj_kundalia
    @raj_kundalia 2 ปีที่แล้ว

    Thanks you for the wonderful explanation.

  • @csedatasceince-a6886
    @csedatasceince-a6886 7 หลายเดือนก่อน

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

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

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

  • @AyushKumar-ju9jj
    @AyushKumar-ju9jj 2 ปีที่แล้ว +1

    Bhai hgg diya tune is explaination me

  • @ankitdubey9310
    @ankitdubey9310 3 ปีที่แล้ว +4

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

  • @bhaveshkumar6842
    @bhaveshkumar6842 3 ปีที่แล้ว

    Thank you

  • @piyushkhandelwal1662
    @piyushkhandelwal1662 ปีที่แล้ว

    if (cnt

  • @lakshmiprasanna7058
    @lakshmiprasanna7058 ปีที่แล้ว

    Understood 💯💯💯

  • @satyamgupta7608
    @satyamgupta7608 2 ปีที่แล้ว

    1:56

  • @editorera239
    @editorera239 3 ปีที่แล้ว +3

    10:48 m smgh ni aya bro

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx 9 หลายเดือนก่อน

    Understood

  • @San-ix7ki
    @San-ix7ki 2 ปีที่แล้ว +2

    didn't get

  • @GauravKumar-dw2ml
    @GauravKumar-dw2ml 2 ปีที่แล้ว

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

  • @sayanNITdgp2025
    @sayanNITdgp2025 ปีที่แล้ว

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

  • @atifhu
    @atifhu 2 ปีที่แล้ว +1

    Python walo se iss sajjan ko kya taqleef hai bhai😂

  • @adarshrai9516
    @adarshrai9516 3 ปีที่แล้ว +1

    Thanks bhai 🙏

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

  • @funenjoynilaypatel4553
    @funenjoynilaypatel4553 2 ปีที่แล้ว +1

    9 march 2022 11:06 pm

  • @rishikantpatel5008
    @rishikantpatel5008 2 ปีที่แล้ว

    Confusion in low ends with median?

  • @jatilyadav4000
    @jatilyadav4000 2 ปีที่แล้ว

    Amazing video

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

  • @krishnams2286
    @krishnams2286 2 ปีที่แล้ว +1

    explaination is very confusing

    • @herculean6748
      @herculean6748 2 ปีที่แล้ว

      yes, it is confusing, I didn't understand why low=1, high=1e9

  • @Anubhav2101
    @Anubhav2101 2 ปีที่แล้ว

    Thanks Bhaiya

  • @____Akash__
    @____Akash__ ปีที่แล้ว +1

    Awesome explanation 🔥🔥🔥 Hattttttttttttttttttttttttttttss offffffffffffffffffffffffffffffff vaiya...

  • @NithishKumar-hx8do
    @NithishKumar-hx8do 3 ปีที่แล้ว +3

    Why are we using the condition

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

  • @dipuprasad9196
    @dipuprasad9196 3 ปีที่แล้ว

    Thank you bhaiya very clear to me it is was

  • @teeyaojha4365
    @teeyaojha4365 ปีที่แล้ว

    not clear :(
    please rerecord this video

  • @mohitverma3235
    @mohitverma3235 2 ปีที่แล้ว

    Awesome bro 🔥🔥🔥🔥

  • @pappu_bakait
    @pappu_bakait 3 ปีที่แล้ว

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

  • @abhijeetkumar2970
    @abhijeetkumar2970 ปีที่แล้ว

    understood

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

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

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

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

  • @tejas7379
    @tejas7379 3 ปีที่แล้ว

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

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

  • @chandlerbing8164
    @chandlerbing8164 ปีที่แล้ว

    very confusing
    other videos are good explained but this just goes over the head

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

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