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

Поділитися
Вставка
  • Опубліковано 15 лип 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

КОМЕНТАРІ • 431

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

    Please watch our new video on the same topic: ua-cam.com/video/N0MgLvceX7M/v-deo.html

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

    Mind got blown away after listening to the optimal solution

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

    mind got blown away after listening to the optimal solution

  • @takeUforward
    @takeUforward  Рік тому +108

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

  • @suyashpurwar631
    @suyashpurwar631 11 місяців тому +87

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

    • @RohanKumar-gy4gl
      @RohanKumar-gy4gl 9 місяців тому +41

      HOLY S... bruh is an einstein for sure

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

      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.

  • @dpxy1599
    @dpxy1599 8 місяців тому +58

    This optimal approach is confusing.

  • @CodeBoost8375
    @CodeBoost8375 Рік тому +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.

  • @vivekdalal1724
    @vivekdalal1724 Рік тому +15

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

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

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

  • @yugal8627
    @yugal8627 Рік тому +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🙂

  • @Manishgupta200
    @Manishgupta200 Рік тому +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 ❤

  • @josephwilliams9
    @josephwilliams9 9 місяців тому +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 ❤

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

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

  • @cinime
    @cinime Рік тому +4

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

  • @devanshulpratapsingh5963
    @devanshulpratapsingh5963 Рік тому +7

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

  • @Atharva_kathiyawadi
    @Atharva_kathiyawadi Рік тому +3

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

  • @krishsachdeva1105
    @krishsachdeva1105 Рік тому +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++

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

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

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

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

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

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

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

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

  • @juliechoudhary9582
    @juliechoudhary9582 Рік тому

    Understood and it's Amazing How you teach.

  • @jaydeepkarena
    @jaydeepkarena Рік тому +3

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

  • @NikitaSingh-kz2ii
    @NikitaSingh-kz2ii Рік тому

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

  • @sunnyvlogs__
    @sunnyvlogs__ Рік тому

    Literally Awesome Explanation , easiest way

  • @surabsebait5409
    @surabsebait5409 Рік тому +1

    Understood, very clearly explained

  • @mgnfy-view
    @mgnfy-view 9 місяців тому +1

    Beautiful explanation!

  • @CodingEnv
    @CodingEnv Рік тому +3

    You are the soul and heart of DSA.

  • @AjayKumar-sx6qo
    @AjayKumar-sx6qo 11 місяців тому

    OMG !!! Awesome explanation.. Thanks Striver

  • @NaveenKumar-xq6ce
    @NaveenKumar-xq6ce Рік тому +3

    Your consistency is admirable @Striver

  • @AyushSharma-ye1xz
    @AyushSharma-ye1xz Рік тому +4

    All videos are very helpful ❤️

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

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

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

    Crystal Clear Explanation!

  • @krishanubiswas6869
    @krishanubiswas6869 7 місяців тому +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...

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

    thank you so much for such a great effort.

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

    Understood,Thank you striver for this amazing video.

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

    best explaination ,just love it!!

  • @prathameshhatkar1911
    @prathameshhatkar1911 Рік тому +3

    Great optimisation 🔥

  • @Akash-yr2if
    @Akash-yr2if Рік тому +2

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

  • @AbhishekSingh-mh2fg
    @AbhishekSingh-mh2fg 10 місяців тому +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.

  • @subhambachar
    @subhambachar 9 днів тому

    just blew my mind, The OP optimal approach 🤯🚀

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

    Thank you for providing such good content

  • @rajatrathore5455
    @rajatrathore5455 Рік тому

    Understood , great explanation

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu 3 місяці тому

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

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

    Thank you so much🥰
    Very much helpful !!

  • @AdarshKeshari-wc2uz
    @AdarshKeshari-wc2uz Місяць тому

    Understood after going through twice
    ❤❤
    Best explanation

  • @shivammotani
    @shivammotani Рік тому

    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.

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

    AMAZING SIR , UNDERSTOOD VERY WELL

  • @myyoutubeisthis
    @myyoutubeisthis Рік тому

    Thank you sir you're great.

  • @rishabhkala2115
    @rishabhkala2115 11 місяців тому

    thanks for this explanation
    understood everything

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

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

  • @FooBar-lb5wf
    @FooBar-lb5wf Місяць тому

    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.

  • @karanveersinghdeora5085
    @karanveersinghdeora5085 Рік тому +1

    Understood very well

  • @user-yw6zj3ir8p
    @user-yw6zj3ir8p 5 місяців тому

    crystal clear approach

  • @TheEleetcoder
    @TheEleetcoder Рік тому

    inspired by you and making videos like you!

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

    Such a great solution ✨

  • @AnkitYadav-sk4nw
    @AnkitYadav-sk4nw Рік тому

    Thank you Bhaiyaa!❤

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

    Understood. Thanks a lot

  • @mashkoorahmad1885
    @mashkoorahmad1885 11 місяців тому

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

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

    Understood. Thank you bro

  • @shloksuman8164
    @shloksuman8164 Рік тому +7

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

    • @takeUforward
      @takeUforward  Рік тому +16

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

  • @nivetha6167
    @nivetha6167 Рік тому +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 10 місяців тому +4

      u are literally me

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

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

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

      ​@@bully9858bro is actually him🗣️ 🔥🔥

  • @pallavi22222
    @pallavi22222 Рік тому

    Superb Explaination

  • @chethanprabhu4475
    @chethanprabhu4475 Рік тому +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  Рік тому +10

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

    • @vivekpatial5614
      @vivekpatial5614 Рік тому

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

  • @ddevarapaga5134
    @ddevarapaga5134 14 днів тому

    wow mindblown amazing understood bro

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

    understood thank you so much bro

  • @NitinKumar-wm2dg
    @NitinKumar-wm2dg Рік тому

    Understood bhaiya, thank you

  • @abdulrehmaan153
    @abdulrehmaan153 Рік тому +2

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

  • @RahulYadav-jk7um
    @RahulYadav-jk7um Місяць тому

    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! ❤

  • @parthtiwari8152
    @parthtiwari8152 11 місяців тому

    Loved ❤ ...
    Understood

  • @shivamsingh7817
    @shivamsingh7817 Рік тому

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

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

    Amazing Bhaiya !

  • @priyotoshsahaThePowerOf23
    @priyotoshsahaThePowerOf23 Рік тому

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

  • @user-ui6op1zc2q
    @user-ui6op1zc2q Рік тому

    just awesome ♥

  • @prasoonmishra995
    @prasoonmishra995 Рік тому +1

    Awesome 👍

  • @user-ui9fw7qj5n
    @user-ui9fw7qj5n 7 місяців тому

    understood striver
    Thanks

  • @itsabhinav04
    @itsabhinav04 Рік тому

    Understood, thanks :)

  • @suyashshinde2971
    @suyashshinde2971 Рік тому +2

    SDE Sheet: Day 1 Problem 1 Done!

  • @myyoutubeisthis
    @myyoutubeisthis Рік тому

    Thank you very very very very much sir

  • @poojithkumar2283
    @poojithkumar2283 Рік тому

    good approach👏👏👏

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

    Understood✅🔥🔥

  • @rohitraj5832
    @rohitraj5832 9 місяців тому +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;
    }
    }
    }

  • @sukritinarang5016
    @sukritinarang5016 4 місяці тому +1

    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

  • @SunnyYadav-zv7hp
    @SunnyYadav-zv7hp Рік тому

    Love you so much bro

  • @yuvrajpatil925
    @yuvrajpatil925 Рік тому

    Thanks 🙏

  • @Se7ven_Plays
    @Se7ven_Plays Рік тому

    Thankyou. Bhai for videos 😶

  • @kushagramishra5638
    @kushagramishra5638 Рік тому +1

    Understood !

  • @GhostVaibhav
    @GhostVaibhav Рік тому +1

    Understood🔥

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Рік тому

    Understood!!! 🔥🐢

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

    thank you sir❣

  • @GauravJain-zo8gt
    @GauravJain-zo8gt 2 місяці тому

    jai jinendra sir understood

  • @shikhajoshi8961
    @shikhajoshi8961 11 місяців тому

    Understood Sir💗🙏

  • @prathiswarangr7879
    @prathiswarangr7879 Рік тому

    Understood ❤

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

    Understood Sir!

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

    Understood!!🙇‍♂

  • @vardhamanbhandari5644
    @vardhamanbhandari5644 Рік тому

    Understood🙌🙌🙌🙌

  • @rajalakshmis7308
    @rajalakshmis7308 Рік тому

    Understood👍🏻

  • @KartikeyTT
    @KartikeyTT 28 днів тому

    tysm sir

  • @nagame859
    @nagame859 Рік тому

    Understood sir🤩

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

    Thank you