Leetcode Set Matrix Zeroes || Intuition + Code + Explanation || O(1) space

Sdílet
Vložit
  • čas přidán 13. 08. 2021
  • Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's, and return the matrix.
    You must do it in place.

Komentáře • 164

  • @probabilitycodingisfunis1
    @probabilitycodingisfunis1  Před 2 lety +18

    Code CPP:
    int m =matrix.size();
    int n = matrix[0].size();
    int x =1;
    int y =1;
    for(int j=0;j

    • @50_manishkumar43
      @50_manishkumar43 Před 2 lety +3

      Outstanding explanation
      Previously I was confused in 3rd approach but after watching the video it is crystal clear wright now
      Thank you soo much Alisha

    • @ANKITKUMAR-iy4he
      @ANKITKUMAR-iy4he Před 2 lety +2

      But the time complexity remains O(mn), isn't it.

    • @nit8826
      @nit8826 Před rokem +1

      @@ANKITKUMAR-iy4he for 2 d matrix time complexity always m*n here main motive to reduce space complexity to constant 🙂

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

    After not understanding code from striver, I understood the solution from this channel. Thanks for it. Though I'm still facing some difficulties in coding and understanding but I looked at solution for 4-5 times and I'm getting better. Thnx

    • @pawxnsingh
      @pawxnsingh Před rokem +1

      same here bro i camed from striver sde sheet/course

    • @Vishaaaaaaaaaal
      @Vishaaaaaaaaaal Před rokem

      same

    • @siddhantprakash.
      @siddhantprakash. Před rokem

      yeah the last approach were he did in O(1) space was unclear.

    • @asthapandey9587
      @asthapandey9587 Před rokem

      ​@@pawxnsingh how many questions per day from striver sheet should be done

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

      yeah bro !

  • @anuragtiwari3032
    @anuragtiwari3032 Před 2 lety +25

    Great explanation again, I had watched around 5-10 videos before this but was only able to understand it after ur video. I wish this channel gets the recognition it deserves

  • @utsavsharma4542
    @utsavsharma4542 Před rokem +2

    Definitely the best explanations, striver has explained the same concepts but the way he explains them seems difficult. You made this problem look so easy

  • @sayanmaity2694
    @sayanmaity2694 Před 2 lety +11

    Recently I found your channel, and honestly whenever I get stuck at some problem after watching some famous youtuber's explanation also I come here to see yours. I really love the way you explain ❤️

  • @siddharthkakade7779
    @siddharthkakade7779 Před rokem +1

    What an explanation 💯💯 times better then striver and everyone over there on CZcams. Got it in the first run through itself.

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

    I watched over 4 videos but didn't understand any, I was finally able to grasp the concept after watching your video. Please keep up the good work. Thank you

  • @zaidshaikh2536
    @zaidshaikh2536 Před 2 lety +1

    Your enthusiasm while explaining deserves more views for your Hardwork.

  • @snehangshuchakraborty1458

    Accidently landed to this video and I must say your channel is underrated.. Full marks on the neat explaination!

  • @__k.abhishek
    @__k.abhishek Před rokem

    Watched 3 videos didn't understand this method. Watching your video i understand it in one attempt. Thanks a lot 💫

  • @subratkumar7359
    @subratkumar7359 Před rokem

    Thanks didi. I didn't understand after watching videos of popular youtubers but completely understood in one pass after watching this explanation.

  • @anirbandhara8835
    @anirbandhara8835 Před 2 lety

    Really great explanation . I have seen many videos but unable to understand their explanation . But you made that crystal clear to me. Thankyou

  • @readbhagwatgeeta3810
    @readbhagwatgeeta3810 Před rokem +1

    How can someone explain so well ? No room left for any doubt. Thank you so much☺️🙏🙏

  • @rajrehman9812
    @rajrehman9812 Před rokem

    Best explanation that I found on the internet for this problem.

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

    Best video of this question. Amezing explanation

  • @siddhisatnalika1231
    @siddhisatnalika1231 Před 2 lety

    Such an amazing approach! Thanks a ton!

  • @harish5466
    @harish5466 Před rokem

    Thank you so mush Alisha... I just watched the entire video once and written code in java ...With the 1st attempt only it got Submited.. The way you explained the concept is very nice. Thank you so much...

  • @TheSankalpAwadhiya
    @TheSankalpAwadhiya Před rokem

    So underrated channel....such a gem content

  • @adityasingh8466
    @adityasingh8466 Před rokem

    you explained it so easily , seriously thank uh

  • @Rizwankhan-ts3gk
    @Rizwankhan-ts3gk Před rokem

    thank you Alisha , honestly when i face any problem to solve question , first i used to find out it on your channel

  • @ASHUTOSHSHARMA-us6hd
    @ASHUTOSHSHARMA-us6hd Před 2 měsíci

    thank you for the explanation, may god bless you.

  • @TheMohit987
    @TheMohit987 Před 2 lety +1

    What a great explanation Alisha. 😊😊😊😊 After watching the concept, I opened leetcode and wrote the code. It worked in first go.
    Then came back here to see your code. It is almost same.
    Just to add, in the first two for loops i.e. to mark x and y as zero, we can break the loop. Here is my code:
    class Solution {
    void setRowColumnZeroes(int[][] matrix){
    boolean isFirstRowHasZeros = false, isFirstColumnHasZeros = false;
    int rows = matrix.length, columns = matrix[0].length;
    for(int i = 0; i < columns; i++){
    if(matrix[0][i] == 0){
    isFirstRowHasZeros = true;
    break;
    }
    }
    for(int i = 0; i < rows; i++){
    if(matrix[i][0] == 0){
    isFirstColumnHasZeros = true;
    break;
    }
    }
    for(int i = 1; i < rows; i++){
    for(int j = 1; j < columns; j++){
    if(matrix[i][j] == 0){
    matrix[0][j] = matrix[i][0] = 0;
    }
    }
    }
    for(int i = 1; i < columns; i++){
    if(matrix[0][i] == 0){
    int row = 1;
    while(row < rows){
    matrix[row][i] = 0;
    row++;
    }
    }
    }
    for(int i = 1; i < rows; i++){
    if(matrix[i][0] == 0){
    int column = 1;
    while(column < columns){
    matrix[i][column] = 0;
    column++;
    }
    }
    }
    if(isFirstRowHasZeros){
    for(int i = 0; i < columns; i++){
    matrix[0][i] = 0;
    }
    }
    if(isFirstColumnHasZeros){
    for(int i = 0; i < rows; i++){
    matrix[i][0] = 0;
    }
    }
    }
    }

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

    The way you vizulasing and teaching us it's incredible heads of you😊

  • @FarmanOfficial777
    @FarmanOfficial777 Před rokem

    Love it yar pehle 3 ghante dekha is video ko samajh nahi aaya fir subha subha uthke fir dekh 2 bari me samajh aa gaya

  • @BECABDULKADIR
    @BECABDULKADIR Před 2 lety

    Great, lovely explanation that make me confident ❤️❤️

  • @harmangrewal3664
    @harmangrewal3664 Před rokem

    mam amazing explanation,i wasn't able to understand this question from striver, you explained it amazingly!!!

  • @abhishekkumargupta3605

    Very nicely explained , thanks a lot..

  • @kanyapandey
    @kanyapandey Před rokem

    You are the best thank you so much for simplifying things 🙏🙏🙏

  • @akshatmathur278
    @akshatmathur278 Před 2 lety

    Thank you so much for a very easy to understand explanation.

  • @abhijitbiradar
    @abhijitbiradar Před rokem

    Thanks for the details video. Your efforts are appreciated

  • @aakashpawan1542
    @aakashpawan1542 Před 2 lety +4

    I watched many videos for understanding this problem, You gave the best explanation to this problem. Subscribed 👍

  • @shivanshgupta1509
    @shivanshgupta1509 Před 2 lety +1

    Best explanation!
    Hands Down.

  • @gauravmishra8782
    @gauravmishra8782 Před rokem

    really helpful !!! nice approach and explaination.

  • @sabaafreensyed6956
    @sabaafreensyed6956 Před rokem

    The explanation is extremely good , Thank you so much

  • @shatrudhankumar7824
    @shatrudhankumar7824 Před 7 měsíci

    You explain beautifully without complexing it.❤

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

    Thanks, striver's explanation was too confusing, finally understood!

  • @shreyaesha001
    @shreyaesha001 Před 2 lety +1

    hands down you're the best

  • @vishal9264
    @vishal9264 Před rokem

    Thank you .. yours explanation was best 😊😊❤

  • @rockeykumar3348
    @rockeykumar3348 Před rokem +2

    This is the best best explanation ever i have seen thanks a lot mam..♥️

  • @abhishekdutt7637
    @abhishekdutt7637 Před rokem

    Thanks for making matrix question easy 😄, great explanation

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

    Alisha is good teacher..i can easily under stand

  • @rashmikushwaha4748
    @rashmikushwaha4748 Před rokem

    great explanation alisha

  • @vibhavsharma2724
    @vibhavsharma2724 Před 2 lety

    Thanks for such a good explanation 🙏🙏

  • @VishalKumar-hh4fw
    @VishalKumar-hh4fw Před 2 lety

    I loved the explaination, thank you

  • @SleepeJobs
    @SleepeJobs Před 2 lety

    Crystal clear. Again.
    Thanks

  • @cs-concepts2901
    @cs-concepts2901 Před rokem +1

    Please make more videos on problem solving, leetcode problems, your explanations are super cool, I eagerly wait for the videos.

  • @sagarramdev
    @sagarramdev Před 2 lety +2

    Superb explanation 👌

  • @jaskiratsingh7508
    @jaskiratsingh7508 Před 2 lety

    awesome explanation, very good

  • @neilstrong1735
    @neilstrong1735 Před rokem

    Youre doing great job

  • @bhavikpunmiya9641
    @bhavikpunmiya9641 Před rokem

    Really Nice Explaination

  • @Joy-ow3pt
    @Joy-ow3pt Před rokem

    you always come with good explanation

  • @amansaxena5620
    @amansaxena5620 Před rokem

    Excellent explaination

  • @satharlagopal9744
    @satharlagopal9744 Před rokem

    Well explained..

  • @sahilsaroha750
    @sahilsaroha750 Před rokem

    Didi you put so much effort in explaining this ques. i am glad i clicked your video first , my lots of time is saved.

  • @adarshjadhav8877
    @adarshjadhav8877 Před rokem

    Very good explanation dear, especially when you have gone from most obvious solution and why we cannot use it to the most optimum solution. So we will never make that mistake when we redo the question. Also I really like when you didn't gave a very difficult code as answer for first timer to understand it. Please keep doing it 😊

  • @AmanSharma-vb5jl
    @AmanSharma-vb5jl Před 2 lety

    U should not settle less than google ,u are awesome seriously

  • @user-zw2xy1se2z
    @user-zw2xy1se2z Před 9 měsíci

    Nicely explained. This explanation was better than striver's explanation for same problem.

  • @sagarpatel8853
    @sagarpatel8853 Před rokem

    loved the explanation...keep up the good work....

  • @krishanpratap3286
    @krishanpratap3286 Před 2 lety

    isme while making the entire row and column 0 can we tak for loop from i =0 instead of i =1

  • @arealist8913
    @arealist8913 Před rokem

    Great explaination didi. I understood the problem really well.

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

    You are too good at teaching ❤

  • @zeeshanulhaq4619
    @zeeshanulhaq4619 Před 2 lety

    Exceptional Explanation.

  • @pulkittakyar9299
    @pulkittakyar9299 Před rokem

    well explained , could u provide pseudo code for brute force where u have use 2 arrays as a marker , would really appreciate it?

  • @navinvenkat3404
    @navinvenkat3404 Před 25 dny

    what is the time complexity for the optimised solution

  • @manistrikes
    @manistrikes Před 2 lety

    very Nice explanation....understood finally🙃

  • @mehranmushraf1277
    @mehranmushraf1277 Před rokem

    Great sister best explanation keep it up 🔥🔥🔥🔥

  • @ravishankar9247
    @ravishankar9247 Před 2 lety +1

    I submitted the same code. When I ran the code, it said accepted but when I entered the submit button, it said wrong answer. Someone Please explain why.....

  • @thesilentcoder828
    @thesilentcoder828 Před 2 lety +1

    your explanation is so easy. make more videos ...

  • @akshatgandhi8988
    @akshatgandhi8988 Před 2 lety

    u explained very very well!

  • @anamikaahmed4887
    @anamikaahmed4887 Před 2 lety

    Very clear explanation!

  • @072-deepakshimahajan3
    @072-deepakshimahajan3 Před 2 lety

    Great Explanation!!

  • @imcoder2250
    @imcoder2250 Před 2 lety

    great Explanation....thankyou

  • @vishalkumargond8548
    @vishalkumargond8548 Před 2 lety

    awesome di

  • @leetcodesolutionsinhindi9779

    Best Explanation, Watched various video, but in this video all the doubts get cleared.. 💯💯🌈

  • @sayansen0361
    @sayansen0361 Před rokem

    Great explanation 🛐

  • @nikhilsai6176
    @nikhilsai6176 Před rokem

    Superb Explanation 👍

  • @TxNet
    @TxNet Před 2 lety

    how can we push the 2 arrays inside the main array? like I don't understood this part

  • @meowaiya5592
    @meowaiya5592 Před rokem

    thanks for the explanation

  • @notmrabhi1
    @notmrabhi1 Před 2 lety

    Thanks for explanation👍

  • @BruteCode2002
    @BruteCode2002 Před rokem

    Very helpful video

  • @YuvrajSingh-xy2gu
    @YuvrajSingh-xy2gu Před rokem

    understood thank you

  • @jatinlanje5741
    @jatinlanje5741 Před rokem

    Well explained!

  • @skhabibahmed4677
    @skhabibahmed4677 Před 2 lety

    nice explanation

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

    thank you didi wonderful explanation

  • @RGMUTEX
    @RGMUTEX Před 21 dnem

    Best Explanation.

  • @AnuragPandey-ni1lo
    @AnuragPandey-ni1lo Před 2 lety

    Nice Explanation :)

  • @krishanpratap3286
    @krishanpratap3286 Před 2 lety

    very well taught

  • @ruhisharma9978
    @ruhisharma9978 Před 2 lety

    what is the time complexity of the final solution

  • @yogitamisal2650
    @yogitamisal2650 Před 2 lety

    Thanks Alisha ♥️

  • @srivanis8328
    @srivanis8328 Před 2 lety

    In this optimize approach method ->Suppose inner matrix is not zero in particular problems what I do ? Please explain me mam....

  • @AkashSharma-ij4sn
    @AkashSharma-ij4sn Před 2 lety

    Thank you

  • @indranilthakur3605
    @indranilthakur3605 Před 2 lety

    What would be the TC for the problem? Btw this is the most intuitive solution I have come across.

  • @abhisheksamari4591
    @abhisheksamari4591 Před 2 lety +1

    masttt smjhayaa

  • @yashyadav6190
    @yashyadav6190 Před 2 lety

    Ma'am this code is not giving runtime error. What is the more optimised way to solve this

  • @info-tech6041
    @info-tech6041 Před rokem

    best expalanation ever

  • @jayeshchaurasiya262
    @jayeshchaurasiya262 Před 2 lety

    Explanation ❣️🔥

  • @sachinpatwal2571
    @sachinpatwal2571 Před rokem

    if the array is [1 1 1, 1 1 1 , 0 1 1]
    x will become 0
    now all element remain untouched and at last loop for x==0 , at that loop it will set zero for row ,but not for the columns why ? how these columns would set zero plz reply

  • @ruhisharma9978
    @ruhisharma9978 Před 2 lety

    sooo good and easily understandable diii...loved it, thankyou so much

  • @sankaranarayanankm7049

    please add video of spiral matrix it will be very helpful

  • @adityarajsinghrathore.

    much better explanation then striver