BS-27. Median in a Row Wise Sorted Matrix

Поділитися
Вставка
  • Опубліковано 11 вер 2023
  • Problem Link:
    Notes/C++/Java/Python codes:
    We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
    Full Course: bit.ly/tufA2ZYt
    You can follow me across social media, all my handles are below:
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    0:00 Introduction of Course

КОМЕНТАРІ • 147

  • @IllIIIIIIllll
    @IllIIIIIIllll 7 місяців тому +74

    In era of every other YT FANG employers leaving their job and selling own courses, Striver is the only legend who's not giving up❤️ and managing both🙌.

    • @22gauravkumar70
      @22gauravkumar70 День тому

      tereko uske job chodne ya na chodne se kya farak pdta hai

  • @himanshuram_ranjan
    @himanshuram_ranjan 9 місяців тому +104

    Thank you so much for your wonderful videos, Plz keep them coming 🙏

  • @abhikundekar4186
    @abhikundekar4186 4 місяці тому +6

    Your one line always keep me running positively, "Life bohot badi hai, dont give up easily, try try try again" .Thanks

  • @nawedzan4904
    @nawedzan4904 4 місяці тому +21

    okay i have a doubt the mid that u calclated which is 7 is based on the above matrix but the below sorted array has 16 elements. this sort made of made the whole explanation confusing
    if anyone is reading this do u agree or did i miss something

  • @ManavMSanger
    @ManavMSanger 7 місяців тому +7

    Finally completed the playlist. Thank you striver !

  • @charlesbabbage6786
    @charlesbabbage6786 3 місяці тому +2

    Finally completed Binary search playlist. This series is Amazing!!! In depth explanations, diverse problems, and great logic building!👏👏👏

  • @pratikkumarsingh8114
    @pratikkumarsingh8114 8 місяців тому +3

    Aatma santusht ho gaya Striver bhaiya ye lecture dekh kar maaza ageya , Big thanks Bhaiya , love you, you are an inspiration for me !!!!!!!!!!!!!!!!

  • @adityarao4157
    @adityarao4157 9 місяців тому +7

    with this i think my intuition became better for using BS in various types of questions
    Thanks RAJ sir

  • @saikumargatla4706
    @saikumargatla4706 10 місяців тому +7

    New video means more knowledge. This consistency is amazing.Understood

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp 9 місяців тому +5

    And Yes Reverse Polarity is also working here as
    *High pointing to an element that is greater than all the elements* and *Low pointing to the smallest element*
    If you dry run then low end up pointing to the answer.
    Thankyou soo much Striver..... I'm just soo damn grateful to you 🙇‍♂️

  • @studynewthings1727
    @studynewthings1727 9 місяців тому +4

    yes, I am from python community didn't find any issue in the course. I think this course is one of the best course. I have taken purchased course also but this is one of the best course.

  • @iammysterious-ud9cf
    @iammysterious-ud9cf 10 місяців тому +76

    Eagerly waiting for Strings and LINKED LISTS😢

    • @cdnggk6455
      @cdnggk6455 9 місяців тому +4

      agle saal aeega wo wala playlist

    • @puneetnj1842
      @puneetnj1842 9 місяців тому

      @@cdnggk6455 really or kidding?

    • @Tam-wc2qm
      @Tam-wc2qm 9 місяців тому

      why?@@cdnggk6455

    • @zanies6288
      @zanies6288 9 місяців тому +1

      Strings me kya pdna h? vo toh question practice krte-krte hi aayega.

    • @iammysterious-ud9cf
      @iammysterious-ud9cf 9 місяців тому +6

      @@zanies6288Improving problem solving of Strings in a brute, better, optimal is much necessary for beginners of DSA.. I would like to remind that it's A TO Z BEGINNER COURSE...🙂

  • @rohitsai806
    @rohitsai806 9 місяців тому +2

    Completed the playlist..! As usual.. OP Striver.. Keep rocking man... Eagerly waiting for your more playlists

  • @Dontpushyour_luck
    @Dontpushyour_luck 8 місяців тому +1

    best playlist. Understood everything!

  • @a2-_fg
    @a2-_fg 10 місяців тому +3

    I really like your way of teaching
    Keep uploading!!!

  • @ibrahimlanre4285
    @ibrahimlanre4285 9 місяців тому +2

    Striver u are really doing a good job and helping thousands of aspiring engineers like me ❤️❤️❤️❤️, please can you add low level design playlist .. like OOP design interviews in c++

  • @amanupadhyay8628
    @amanupadhyay8628 9 місяців тому +1

    please keep uploading bhaiya this series at least 1 video a day.. ThankYOu ❤

  • @nilimsankarbora5911
    @nilimsankarbora5911 22 дні тому

    Previously Studied Binary Search 9 months ago , now again done a broad revision from you , now concepts are more crystal and clear than before . Thanks Striver for your continuous effort to reform the IT Industry in India by teaching the new generations topmost Coding skills . God bless you . Will now revise both Graph and DP from you shortly . 😊💌❤

  • @udatyadeb101
    @udatyadeb101 5 місяців тому +1

    understood! and finally completed this binary search playlist. Did learn a lot!!! Thanks Striver....

  • @user-kc7bx6rc9j
    @user-kc7bx6rc9j 10 місяців тому +9

    Please try to upload a video daily Placements already started and yours videos are really helpful

  • @senseiAree
    @senseiAree 8 місяців тому +7

    Hey Striver, Thanks for the wonderful videos... I am unable to grasp the concept, maybe because its 4:50am and I have exhausted my daily quota of brain usage... Haha, will try this one later...❤

  • @shantipriya370
    @shantipriya370 6 місяців тому +1

    thanks for the wonderful series..

  • @abdulrauf7815
    @abdulrauf7815 10 місяців тому +7

    Eagerly waiting for strings❤❤

  • @Ajay-cv1zs
    @Ajay-cv1zs 7 місяців тому +5

    Doubt - what makes it sure that the answer will be present in the matrix? Like how can we say the answer we found will always be in the matrix?

    • @Peeeacee
      @Peeeacee 5 місяців тому +3

      Even I have the same doubt. Lemme know if you get that.

    • @aletivardhan6679
      @aletivardhan6679 5 місяців тому

      ++ Is there some kind of proof for the same? Please let me know once you get it.

    • @kushagrajain9493
      @kushagrajain9493 4 місяці тому

      @@aletivardhan6679
      @palakkalsi8595
      @Ajay-cv1zs , striver has replied on this issue on one of the comment, let me paste here, "this is why we keep moving low and high, and we don't stop. Its bound to stop at a number which is answer. Because if the numbers are [1,5, 6, 7, 11]
      It can never stop at 9 because 8,9,10 all of them will have same number of elements on left."

    • @priyanshuagarwal4334
      @priyanshuagarwal4334 2 місяці тому

      See if some element in not present and it has

  • @AbhishekKumar-dl6ko
    @AbhishekKumar-dl6ko Місяць тому

    completed BIinary Search playlist on 12/05/24... Explanation and Content was awesome ....

  • @ranjeet_sohanpal
    @ranjeet_sohanpal 3 місяці тому +1

    Its crazy I am unable to solve the problem on my own until I watch the logic. I hope I improve this.

  • @stith_pragya
    @stith_pragya 4 місяці тому +2

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

  • @arujain1690
    @arujain1690 6 місяців тому

    Happy to share that i was able to solve brute but couldnt do the optimal

  • @C1_01_AishwaryaTatiwar
    @C1_01_AishwaryaTatiwar 3 дні тому

    Understood!!! Please make a playlist of strings as well,Thankyou.

  • @chiragbansod8252
    @chiragbansod8252 3 місяці тому

    understood man.. Completed this playlist also, Great teacherr🤩

  • @ansh6530
    @ansh6530 9 місяців тому

    Loved it ❤

  • @saillaanil6948
    @saillaanil6948 9 місяців тому +7

    Bhaiya can you make next playlist on *greedy algorithms*. No one in youtube is having a proper videos on it.

  • @NazeerBashaShaik
    @NazeerBashaShaik 2 місяці тому

    Understood, thank you.

  • @VishalKumar-uk5uc
    @VishalKumar-uk5uc 10 місяців тому +1

    Brother you are god for me 💖

  • @circastic2860
    @circastic2860 5 місяців тому +2

    Thanks a lot striver , I was able to crack amazon interview through your series.

  • @arjunchittam5498
    @arjunchittam5498 9 місяців тому

    Very nice explanation

  • @Shaunak...
    @Shaunak... 9 місяців тому

    you are my role model

  • @debangshudey5736
    @debangshudey5736 8 місяців тому +6

    Striver please upload videos on strings and linked list of A2Z dsa course i am eagerly waiting PLEASE

  • @xaby5349
    @xaby5349 6 місяців тому +4

    Sir ,
    Is it okay if the median answer that we are returning is not in the matrix . Because in some cases mid value (average of high & low) may be not present in the matrix , but numbers " lessequal " than this value are more than "req" , which satisfies the condition so it will be returned.

    • @user-ge9uh9vs9m
      @user-ge9uh9vs9m 6 місяців тому

      have you got your issue resolved yet or not

    • @user-ge9uh9vs9m
      @user-ge9uh9vs9m 6 місяців тому

      because I'm thinking the same thing for half hour

    • @aayush5474
      @aayush5474 Місяць тому

      I also thought the same.

  • @ranvijaysharma6697
    @ranvijaysharma6697 5 місяців тому +3

    Sorry, watched the video couple of times but didn'y understood the thought process, can you help please....

  • @xoxoxo7313
    @xoxoxo7313 3 місяці тому

    Damn this guy is top notch!

  • @aashitAgrawal
    @aashitAgrawal 6 місяців тому

    nice explanation 👍

  • @venkateshhs3776
    @venkateshhs3776 4 місяці тому

    Thank you 🙂

  • @priyaanshusoni
    @priyaanshusoni Місяць тому +2

    PLEASE BRING STRINGS PLAYLIST SOON !!!!!

  • @nikhitawatpal3636
    @nikhitawatpal3636 8 місяців тому +2

    sir can you tell when are you going to upload the next videos as we are waiting from 1 month now?

  • @YourCodeVerse
    @YourCodeVerse 6 місяців тому

    Understood✅🔥🔥

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l 4 місяці тому

    Thank you Bhaiya

  • @alessandrocamilleri1239
    @alessandrocamilleri1239 10 місяців тому +10

    Thalaivar. Striver ka hukum.

  • @Dipanshutripathi2407
    @Dipanshutripathi2407 9 місяців тому

    Mission Accomplished sir ji

  • @adityajain2426
    @adityajain2426 8 місяців тому +4

    when will you upload String videos?

  • @dreamyme543
    @dreamyme543 9 місяців тому +1

    Understood🙃

  • @pardhi8959
    @pardhi8959 10 місяців тому +1

    Bhaiya ❤

  • @hat_awesome21
    @hat_awesome21 9 місяців тому +6

    bro plz upload strings and linked list

  • @nihalsingh6233
    @nihalsingh6233 7 місяців тому

    Understood!!

  • @augustinradjou3909
    @augustinradjou3909 9 місяців тому +5

    Striver start sliding windows and greedy atleast provide a basics video😢 i solved the linked list fully now it was good but greedy and sliding windows looks like something big can you give a start

  • @Bmbawavikram
    @Bmbawavikram 9 місяців тому

    Could you please tell me which tool you uses for teaching ?

  • @stormgaming4442
    @stormgaming4442 7 місяців тому

    Which app do you use sir for notes?😊

  • @lifehustlers164
    @lifehustlers164 6 місяців тому +2

    bhai strings ki playlist laado ! will be of great help!!!

  • @user-xm6ue3cy2k
    @user-xm6ue3cy2k 2 місяці тому

    Thanks

  • @anand_yv
    @anand_yv 9 місяців тому

    Understood

  • @praq6889
    @praq6889 2 місяці тому

    we can assign low = matrix[0][0] and high = matrix[n-1][m-1]

  • @baskarraja8451
    @baskarraja8451 10 місяців тому +1

    New question from binary search

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp 9 місяців тому

    If you observe then after the first solution that was *n* * *m* *** *(n* *** *m* *** *log2(nm))*
    Instead of removing the -log(nm)-
    We can Optimize that instead of putting all the elements in an array we can sort the 2D Matrix itself and use the formula of total_column / index
    And this will work because the rows and cols will be odd everytime
    So the TC will be *(n* *** *m* *** *log2(nm))*

    • @771aryan
      @771aryan 8 місяців тому

      The TC originally is n*m*log(2nm) because , you will use O(n*m) to traverse all elements in the 2d array, and then you will sort the n*m elements using inbuilt function, so TC will be O(n*m + n*m*log(2nm))

  • @shivashankar6043
    @shivashankar6043 9 місяців тому

    can anyone tell me, what software he is using for sketching in this video

  • @omkarshendge5438
    @omkarshendge5438 11 годин тому

    brother there is no 6 in that matrix from where are you taking this 6 that you have written in the 1D array

  • @havefunwithshort
    @havefunwithshort 2 місяці тому +1

    understood

  • @mritunjaykumar947
    @mritunjaykumar947 8 місяців тому +1

    Striver, here the code looks all great but how are we navigating the matrix here, I am very confused regarding that, the code is navigating as we have used an array, with all the number. But it is very different scenario in the matrix.

    • @mritunjaykumar947
      @mritunjaykumar947 8 місяців тому

      Also the final answer/code for this problem isn't available in the description. Can you please look into it?

  • @sumitkamble_
    @sumitkamble_ 9 місяців тому

    Just wow

  • @ShubhamKumar-re4zv
    @ShubhamKumar-re4zv 9 місяців тому +2

    Bhaiya linked list aur string ki bhi videos aane wali hai kya? If yes then what will be the timeline so that usse ki hisab se preparation ki planning krte

    • @ultimatescience3842
      @ultimatescience3842 9 місяців тому

      bhai striver ne poori complete karwa diya hai kya dsa playlist? aur kya videos sequence mein hain?
      tumko kitna fayda hua?
      kitna padhe?

    • @RAHULSINGH-cd6gl
      @RAHULSINGH-cd6gl 7 місяців тому

      ​@@ultimatescience3842pura complete nhi hua hai........sequence mat Haan jaisa a-z DSA playlist me hai waise padhna start Karo bahut faida hoga......Maine personally padha hai islia bata sakta hu

  • @harshitjaiswal9439
    @harshitjaiswal9439 4 місяці тому

    understood.

  • @vinayyelleti2714
    @vinayyelleti2714 9 місяців тому

    Will this work if array is sorted Ina way that last index of first row is less than first index of second row and so on

    • @amaldevps2164
      @amaldevps2164 9 місяців тому

      Yes, in that case last index of second row should be the largest value
      Eg [[1,2,3],[4,4,4]]

  • @learningstuff4578
    @learningstuff4578 2 дні тому

    What if the input arr is [[1,2,3],[1,2,3],[1,2,3]] . then (n * m) /2 will not hold. Can someone please clarify ?

  • @nmkcomps
    @nmkcomps 9 місяців тому +4

    How can we be sure low+mid/2 belongs to the matrix

    • @takeUforward
      @takeUforward  9 місяців тому +8

      this is why we keep moving low and high, and we don't stop. Its bound to stop at a number which is answer. Because if the numbers are [1,5, 6, 7, 11]
      It can never stop at 9 because 8,9,10 all of them will have same number of elements on left.

    • @learningstuff4578
      @learningstuff4578 2 дні тому

      @@takeUforward What if array is [[1,2,3],[1,2,3],[1,2,3]] . In that case how will the req = (n*m)/2 will hold ?

  • @kunal5077
    @kunal5077 7 днів тому

    Please make playlist on strings
    sir

  • @rushikstudies6365
    @rushikstudies6365 9 місяців тому +1

    Striver I'm a final year student,now campus placements are going on so can you please tell when this course may finish...

    • @zanies6288
      @zanies6288 9 місяців тому

      If you are final year student, don't waste on this course. This is for beginners and people who have a lot of time. Just read the articles on takeuforward solve some problems on leetcoee u will learn more in less time.

  • @sachinsoma5757
    @sachinsoma5757 9 місяців тому

    Can you please teach us maths required for competitive programming.

  • @mannsavani
    @mannsavani 3 місяці тому

    does anyone know, which companies have asked this question?

  • @gauravsahu8174
    @gauravsahu8174 9 місяців тому +2

    Hey Striver, I have one doubt will you replace all the old videos(DP series, Binary Search Trees, Graphs and other videos) with new videos or will you continue with the old one, so that we can wait for new one or we can continue can you please give some clarification on this.
    By the way you videos are really helpful. Thanks for such free content.🙏

    • @bishalkundu7592
      @bishalkundu7592 9 місяців тому

      No those videos are (Trees, DP and Graph) pretty new. And bhaiyaa will not be replacing those videos.

    • @ultimatescience3842
      @ultimatescience3842 9 місяців тому

      @@bishalkundu7592 is hsi playlist completely updated and complete? Are all the videos arranged in serial?

    • @bishalkundu7592
      @bishalkundu7592 9 місяців тому +1

      @@ultimatescience3842 what do u mean by hsi playlist?

    • @ultimatescience3842
      @ultimatescience3842 9 місяців тому +1

      @@bishalkundu7592 sorry bro, I meant "His". Matlab poora complete hai dsa? aur agar playlist ko follow karein A to Z toh kya saare videos serial mein hain?
      Plus mai ekdom new hoon programming mein, abhi third year start hua. Mai c++ soch raha seekhne ko toh wo kaha se seekhun? c++ with dsa karne ki soch raha hoon. Please bro thoda detail mein bata dena:)

  • @astrid_6622
    @astrid_6622 5 місяців тому +2

    gfg k 4 hzar a course kharid kar striver ki playlist se padh rahi hu🥲❤

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 9 місяців тому +1

    BF approach.
    Public class solution {
    Public static int find median(int [][]matrix,int m,int n){
    Array list list =new Array list ();
    for(int i=0;i

  • @adarshnikhil4499
    @adarshnikhil4499 7 місяців тому +2

    Bro! Escape the matrix

  • @nikhilkumarjamwal5322
    @nikhilkumarjamwal5322 7 місяців тому

    Can't it be like O(logn * logn)
    For max element -> O(logn) as well
    ???

  • @kamakshijayaraman3747
    @kamakshijayaraman3747 6 місяців тому +3

    i dont understand

  • @SatyaSaiPrasad-ot4jl
    @SatyaSaiPrasad-ot4jl Місяць тому

    Where can I get Java code?

  • @parthchaudhary5134
    @parthchaudhary5134 9 місяців тому +1

    Striver bhai sach sach batana iska optimal solution aapne bina solution dekhe apne aap soch liya tha kya ??? And other people also tell me this...because it seems to be impossible to think the optimal sol by myself...

    • @HarshKumar-hn8ss
      @HarshKumar-hn8ss 8 місяців тому

      Bhai humari bhi yahi doubt h ! Ki ye khdse aana toh impossible lagtah

  • @roshansalian692
    @roshansalian692 9 місяців тому

    Binary Search playlist done?

  • @Mr_X_FIFA
    @Mr_X_FIFA 7 місяців тому +1

    Ab video ni ayegi??😢
    Aapne bola tha daily ayegi ab

  • @Iammuslim947
    @Iammuslim947 10 місяців тому +2

    1st view 1st comment

  • @sarthakkumarjain4104
    @sarthakkumarjain4104 9 місяців тому

    Hi bhaiya can connect by some chance.recently i got call from scaler and they got very convincing as well as confusion. So I wanted to connect with you plz it Will be a big help.There is no problem in payment but plz guide me what should I do🙏

    • @VishalGupta-xw2rp
      @VishalGupta-xw2rp 9 місяців тому

      Have faith in Striver and solve more questions, no need of anything else

  • @JIGARSINGTHAKOR-yy6qp
    @JIGARSINGTHAKOR-yy6qp 2 місяці тому +1

    just try for 1 2 3 4 5 for better clarity why always returning low as answer.

  • @PIYUSHKUMAR-rz6yz
    @PIYUSHKUMAR-rz6yz 2 місяці тому

    This is my simple and easy to understand O(log(2000) * R * log(C)) ~ O(11 * R * log(C)) code:
    int median(vector &matrix, int R, int C){
    int l = 1, r = 2000;
    while(l

  • @cinemaahall
    @cinemaahall 4 місяці тому

    Can't we do this l=m*n/2. d=l/rows. R=l%rows+d. Ans=matrix[d][R]

  • @SAACHIPANDEY
    @SAACHIPANDEY 17 днів тому

    9:10

  • @devarapallivamsi7064
    @devarapallivamsi7064 4 місяці тому

    Can someone verify whether the following code is flawless? (I couldn't verify more than running it with the test case in the video)
    (Python)
    import math
    mat = [[1, 3, 6], [2, 6, 9], [3, 6, 9]]
    rows = len(mat)
    cols = len(mat[0])
    mini = math.inf
    maxi = -math.inf
    for i in range(len(mat)):
    mini = min(mini, mat[i][0])
    maxi = max(maxi, mat[i][cols-1])
    low = mini
    high = maxi
    required = (rows*cols) // 2 + 1
    while low

  • @cheating_lemon
    @cheating_lemon 7 днів тому

    I gotta say this one is super confusing.

  • @sudarshanwadajkar8323
    @sudarshanwadajkar8323 9 місяців тому

    us

  • @sallu_-bhai
    @sallu_-bhai 5 місяців тому +1

    Mujhe ye median wale problem itne bekar lagti h 😢

  • @chaitanyaphaneendra3111
    @chaitanyaphaneendra3111 8 місяців тому +2

    you don't know most of the thing you are talking about!!

  • @WolfieIsLive
    @WolfieIsLive 2 місяці тому +2

    not a good explaination...

  • @satwikbhardwaj123
    @satwikbhardwaj123 7 місяців тому

    you are so bad in explaining

    • @IllIIIIIIllll
      @IllIIIIIIllll 7 місяців тому +1

      Stf,u kid.

    • @kushagrajain9493
      @kushagrajain9493 4 місяці тому

      bro watch complete video in one go with full concentration and without any distraction, and repeat it once again if you are not getting, you will definitely understand