Set Matrix Zeroes | O(1) Space Approach | Brute - Better - Optimal

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • Problem Link: bit.ly/3CukQke
    Notes/C++/Java/Python codes: takeuforward.org/data-structu...
    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
    00:40: Problem statement
    01:49: Brute-force solution
    05:13: - Code
    06:28: - Complexity
    07:10: Better solution
    12:16: - Code
    13:49: - Complexity
    14:17: Optimal solution
    23:24: - Code
    29:02: - Complexity

Komentáře • 445

  • @takeUforward
    @takeUforward  Před 10 měsíci +27

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

  • @saisree04
    @saisree04 Před 2 měsíci +73

    Mind got blown away after listening to the optimal solution

  • @aaryakapoor8352
    @aaryakapoor8352 Před 7 dny +6

    mind got blown with the optimal approach

  • @takeUforward
    @takeUforward  Před rokem +110

    Let's march ahead, and create an unmatchable DSA course! ❤
    Use the problem links in the description.

  • @suyashpurwar631
    @suyashpurwar631 Před 11 měsíci +96

    I was able to do the second approach by myself and I'm feeling really good about it!

    • @RohanKumar-gy4gl
      @RohanKumar-gy4gl Před 9 měsíci +43

      HOLY S... bruh is an einstein for sure

    • @adityamadhav1509
      @adityamadhav1509 Před 11 dny

      its not a big deal though, but it really ensures that u r growing as a coder ,keep it up bruh.regarding second approach i though that instead of using two arrays row and column,we can just use one array of pair type where each element of the array is a pair whose first element is ,arked row and second elemen is marked column.

    • @Carson00_11
      @Carson00_11 Před 5 dny

      i am the only dumb then because i cant do anything

    • @jacobblack2544
      @jacobblack2544 Před 3 dny

      @@Carson00_11 yes XD

  • @dpxy1599
    @dpxy1599 Před 9 měsíci +79

    This optimal approach is confusing.

  • @CodeBoost8375
    @CodeBoost8375 Před rokem +82

    Understood! Very well 🔥🔥🔥. And half a hour to example every step from intuition ---> approach till code it shows how you work hard to provide such wonderful video's thanks a lot for this efforts brother.

  • @jatinsharma1595
    @jatinsharma1595 Před 7 měsíci +14

    Understood. Happy that I came up with the better approach by myself, seriously blown away by the optimal approach. Thank you so much Striver

  • @saisree04
    @saisree04 Před 2 měsíci +18

    mind got blown away after listening to the optimal solution

  • @yugal8627
    @yugal8627 Před rokem +4

    OMG , I had watched many tutorials for this problem but never understood it clearly . Thankyou very much for your step-by-step detailed explanation , looking for more content from you in future🙂

  • @vivekdalal1724
    @vivekdalal1724 Před rokem +15

    this is the only study related playlist which im binging by choice and loving it

  • @Manishgupta200
    @Manishgupta200 Před rokem +12

    Really amazing Striver. In-place space optimisation method is really out of my imagination. you make everyting real in very much optimal way. Thankyou Striver for such an amazing tutorial ❤

  • @devanshulpratapsingh5963

    So desperately trying this question for 2 days wasn’t able to optimise it, Now I can❤🔥

  • @cinime
    @cinime Před rokem +4

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

  • @krishsachdeva1105
    @krishsachdeva1105 Před rokem +4

    Bhaiya abhi shayad itne views nhi aarhe but rojj video daalte raho iss course ko complete karna and this will smash all education viewing records.
    Salute++

  • @dxan
    @dxan Před 4 měsíci +2

    Your teaching skills are very well and I must say they are on another level. Thank you so much for the content.

  • @josephwilliams9
    @josephwilliams9 Před 9 měsíci +27

    Code from older video is better.
    Also I understood the intuition in this video's explanation by understanding it from older video.
    A request - PLEASE DON'T DELETE OLDER VIDEOS EVER, THEY TOO ARE GEM ❤

  • @jaydeepkarena
    @jaydeepkarena Před rokem +3

    Great explanation Raj. Thanks for creating this videos. Keep making videos like this. I have just started your SDE sheet for learning DSA

  • @hari7110
    @hari7110 Před 5 měsíci +1

    super bro, i got 1st approach and was scratching my head to optimize it , watched last method twice now i understood🤩

  • @Atharva_kathiyawadi
    @Atharva_kathiyawadi Před rokem +3

    along with i really learn how to write clean code & improve readability !! thanks striver

  • @AbhishekSingh-mh2fg
    @AbhishekSingh-mh2fg Před 10 měsíci +8

    Recently started learning DSA, i was able to come up with the same approach as 1st and 2nd, even though I couldn't complete it but I'm happy I came with some approaches.
    Thanks for this great explanation.

  • @hashcodez757
    @hashcodez757 Před 2 měsíci +1

    great brother!!
    just can't imagine the optimizations you made
    hats off sirr!!

  • @NikitaSingh-kz2ii
    @NikitaSingh-kz2ii Před rokem

    watched the video thrice to finally get optimal approach to my head.
    thankyou for the efforts🤗🤗🤗

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

    You are my motivation to solve the dsa problems every day. Thanks for providing these videos, it helps a lot🔥

  • @yashwairagade3677
    @yashwairagade3677 Před 4 měsíci +2

    U r a legend bro i am impressed by your problem solving skills

  • @AjayKumar-sx6qo
    @AjayKumar-sx6qo Před 11 měsíci +1

    OMG !!! Awesome explanation.. Thanks Striver

  • @NaveenKumar-xq6ce
    @NaveenKumar-xq6ce Před rokem +3

    Your consistency is admirable @Striver

  • @CodingEnv
    @CodingEnv Před rokem +3

    You are the soul and heart of DSA.

  • @krishanubiswas6869
    @krishanubiswas6869 Před 7 měsíci +3

    Thanks striver, ....however i would like to mention my code....when i solved the code by myself....i used a treemap to keep an account of the zeroes.....and then iterated through the map turning all the stored rows and columns to 0....however actually this approach came to my mind from your vertical order traversal of binary tree where you used almost the same data structure....and my solution was accepted (though the T.C was bad)....but still thanks for helping to build me my own approach....and the optimal solution was superb...

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

    Very good algorithm .... the optimal one is really good. Thanks a lot, sir!

  • @sunnyvlogs__
    @sunnyvlogs__ Před rokem

    Literally Awesome Explanation , easiest way

  • @juliechoudhary9582
    @juliechoudhary9582 Před rokem

    Understood and it's Amazing How you teach.

  • @AyushSharma-ye1xz
    @AyushSharma-ye1xz Před rokem +4

    All videos are very helpful ❤️

  • @surabsebait5409
    @surabsebait5409 Před rokem +1

    Understood, very clearly explained

  • @mgnfy-view
    @mgnfy-view Před 9 měsíci +1

    Beautiful explanation!

  • @sakthipriya8653
    @sakthipriya8653 Před 8 měsíci +4

    Understood sir, very great explanation. I was very excited in the 7th minute itself. 🔥🔥🔥

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

    Understood,Thank you striver for this amazing video.

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu Před 3 měsíci

    watched your video ...then others video...then again your video ...then finally understood it😇😇

  • @subhambachar
    @subhambachar Před 18 dny

    just blew my mind, The OP optimal approach 🤯🚀

  • @prathameshhatkar1911
    @prathameshhatkar1911 Před rokem +3

    Great optimisation 🔥

  • @shivammotani
    @shivammotani Před rokem

    IDK why I felt the older video was more good. Found that one to be better. Even optimal code for that one is easier to understand.

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

    Crystal Clear Explanation!

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

    best explaination ,just love it!!

  • @ankitasharma3930
    @ankitasharma3930 Před 10 měsíci

    thank you so much for such a great effort.

  • @AdarshKeshari-wc2uz
    @AdarshKeshari-wc2uz Před měsícem

    Understood after going through twice
    ❤❤
    Best explanation

  • @luckydev9006
    @luckydev9006 Před 10 měsíci

    Thank you for providing such good content

  • @user-ik3qu5uy5e
    @user-ik3qu5uy5e Před 5 měsíci

    AMAZING SIR , UNDERSTOOD VERY WELL

  • @chethanprabhu4475
    @chethanprabhu4475 Před rokem +2

    I had not understood when I watched it 2-3 days back. Looks like I had watched a video which was recorded 2 years back lol. But this new video is crisp clear

    • @takeUforward
      @takeUforward  Před rokem +10

      Yes re-rrecorded, the previous videos were for people who already knew dsa

    • @vivekpatial5614
      @vivekpatial5614 Před rokem

      ​@@takeUforward Your teaching skills are on another level :)

  • @FooBar-lb5wf
    @FooBar-lb5wf Před měsícem

    Amazing explanation, thank you! For the second pass through the array, I tried a slighly shorter approach which seems to work as well (tested on Leetcode). Process the elements bottom to top, right to left. This ensures that an element (i,j) is always updated before its row indicator (matrix[i][0]) and col indicator (col0 if j==0 else matrix[0][j]) are processed. We can then update them through single pair of loops over the array and we may not need special handling for matrix[0][0] and col0 elements.

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

    Thank you so much🥰
    Very much helpful !!

  • @Akash-yr2if
    @Akash-yr2if Před rokem +2

    Gained some Brain Cells After doing the Optimized, Still getting in my head, Damn Solution 🤯🤯

  • @rajatrathore5455
    @rajatrathore5455 Před rokem

    Understood , great explanation

  • @karanveersinghdeora5085
    @karanveersinghdeora5085 Před rokem +1

    Understood very well

  • @sanjayv-ef6ey
    @sanjayv-ef6ey Před dnem

    I have a seen a ad full for u bhai thanks

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

    Such a great solution ✨

  • @user-yw6zj3ir8p
    @user-yw6zj3ir8p Před 5 měsíci

    crystal clear approach

  • @sukritinarang5016
    @sukritinarang5016 Před 5 měsíci +2

    The brute force solution that set values to -1 instead of 0 will not work in some test cases as constraints are mentioned as -2^31

  • @TheEleetcoder
    @TheEleetcoder Před rokem

    inspired by you and making videos like you!

  • @abdulrehmaan153
    @abdulrehmaan153 Před rokem +2

    You just added one more #fan in your infinte length array ❤

  • @mashkoorahmad1885
    @mashkoorahmad1885 Před rokem

    NEXT LEVEL man 😍😍🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥loved your videos

  • @rishabhkala2115
    @rishabhkala2115 Před 11 měsíci

    thanks for this explanation
    understood everything

  • @shloksuman8164
    @shloksuman8164 Před rokem +7

    Optimal approach was quite tedious to understand, however , I got it after writing down the code again myself

    • @takeUforward
      @takeUforward  Před rokem +17

      Yes that is the reason I went slow and long, but writing it yourself helps to clear so many things.

  • @RahulYadav-jk7um
    @RahulYadav-jk7um Před měsícem

    Was able to come up with better solution but did little mistake in the implementation , happy to see that I am now able to come with logical approach to solve problems
    All thanks to striver bhaiya! ❤

  • @pallavi22222
    @pallavi22222 Před rokem

    Superb Explaination

  • @user-cz4lk8qi2q
    @user-cz4lk8qi2q Před 5 měsíci

    Amazing Bhaiya !

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

    Understood. Thank you bro

  • @suyashshinde2971
    @suyashshinde2971 Před rokem +2

    SDE Sheet: Day 1 Problem 1 Done!

  • @palak443
    @palak443 Před 9 měsíci +3

    in first approch if the matrix numbers range is of int then what unique value can we take?

  • @AnkitYadav-sk4nw
    @AnkitYadav-sk4nw Před rokem

    Thank you Bhaiyaa!❤

  • @ddevarapaga5134
    @ddevarapaga5134 Před 23 dny

    wow mindblown amazing understood bro

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

    Understood. Thanks a lot

  • @myyoutubeisthis
    @myyoutubeisthis Před rokem

    Thank you sir you're great.

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

    Understood✅🔥🔥

  • @prasoonmishra995
    @prasoonmishra995 Před rokem +1

    Awesome 👍

  • @priyotoshsahaThePowerOf23

    First code in spreadsheet and got some feel🥵😱❣❣

  • @nivetha6167
    @nivetha6167 Před rokem +24

    You gave me hope when it comes to dsa... I'm too late being misled by other videos, but now after discovering your sde sheet, I have started to figure everything out in a planned manner... soooo... thank youuuuuuuuuuuu!!!!

    • @bully9858
      @bully9858 Před 10 měsíci +4

      u are literally me

    • @nivetha6167
      @nivetha6167 Před 10 měsíci

      @@bully9858 all the best with your coding Journey :⁠-⁠)

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

      ​@@bully9858bro is actually him🗣️ 🔥🔥

  • @NitinKumar-wm2dg
    @NitinKumar-wm2dg Před rokem

    Understood bhaiya, thank you

  • @parthtiwari8152
    @parthtiwari8152 Před 11 měsíci

    Loved ❤ ...
    Understood

  • @user-ui6op1zc2q
    @user-ui6op1zc2q Před rokem

    just awesome ♥

  • @poojithkumar2283
    @poojithkumar2283 Před rokem

    good approach👏👏👏

  • @itsabhinav04
    @itsabhinav04 Před rokem

    Understood, thanks :)

  • @kushagramishra5638
    @kushagramishra5638 Před rokem +1

    Understood !

  • @GhostVaibhav
    @GhostVaibhav Před rokem +1

    Understood🔥

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

    understood thank you so much bro

  • @user-is6ky7pp2n
    @user-is6ky7pp2n Před 2 měsíci

    Understood !!

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Před rokem

    Understood!!! 🔥🐢

  • @HARSHA_27
    @HARSHA_27 Před 8 měsíci

    Understood!!🙇‍♂

  • @Se7ven_Plays
    @Se7ven_Plays Před rokem

    Thankyou. Bhai for videos 😶

  • @shivamsingh7817
    @shivamsingh7817 Před rokem

    Thank you so much bhaiya ❤️❤️❤️❤️

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

    for optimal approach, while filling the matix, instead we can directly traverse the matrix In reverse order so that matrix[0][0] will be affected at last. i mean run loop for(row=m-1 to 0) { for(col=n-1 to 0)}. it worked 😀😀
    //fill the matrix
    for(int i=m-1;i>=0;i--){
    for(int j=n-1;j>=0;j--){
    if(j==0){
    if(col0==0)matrix[i][j]=0;
    }
    else{
    if(matrix[i][0] == 0 || matrix[0][j] == 0)
    matrix[i][j]=0;
    }
    }
    }

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

    Understood Sir!

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

    One of the best optimal approach

  • @karanhaldar755
    @karanhaldar755 Před 4 měsíci +1

    thankjs a lot bro
    I've watched lots of paid videoes and after that i came here to this master piece playlist
    I have no words how much it helps me to crack a job
    guys do not buy any DSA courses
    just watch all the videoes it will be enough to crack any DSA interview🤗🥰🥰🥰🥰🥰🥰

  • @prathiswarangr7879
    @prathiswarangr7879 Před rokem

    Understood ❤

  • @smileyyyy7372
    @smileyyyy7372 Před měsícem +1

    May god bless you striver 🙏🙏

  • @vardhamanbhandari5644

    Understood🙌🙌🙌🙌

  • @nagame859
    @nagame859 Před rokem

    Understood sir🤩

  • @shikhajoshi8961
    @shikhajoshi8961 Před 11 měsíci

    Understood Sir💗🙏

  • @rajalakshmis7308
    @rajalakshmis7308 Před rokem

    Understood👍🏻

  • @SunnyYadav-zv7hp
    @SunnyYadav-zv7hp Před rokem

    Love you so much bro