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

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2024

ความคิดเห็น • 173

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

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

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

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

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

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

      bhai time complexity ?

  • @Akash-yr2if
    @Akash-yr2if ปีที่แล้ว +52

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

      same here bro i camed from striver sde sheet/course

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

      same

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

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

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

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

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

      yeah bro !

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

    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

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

  • @NinjaDevPlays
    @NinjaDevPlays 9 หลายเดือนก่อน +1

    Best video of this question. Amezing explanation

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

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

    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

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

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

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

    this explanation was so so good!! such an underrated channel. tysm for this content. After not understanding from striver, I came here and I was able to understand so well!

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

    Your enthusiasm while explaining deserves more views for your Hardwork.

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

    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

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

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

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

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

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

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

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

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

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

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

  • @__k.abhishek
    @__k.abhishek 2 ปีที่แล้ว

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

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

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

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

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

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

    hands down you're the best

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

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

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

    Thanks for the details video. Your efforts are appreciated

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

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

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

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

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

    You explain beautifully without complexing it.❤

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

    Great explaination didi. I understood the problem really well.

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

    So underrated channel....such a gem content

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

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

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

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

    really helpful !!! nice approach and explaination.

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

    The explanation is extremely good , Thank you so much

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

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

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

    Very nicely explained , thanks a lot..

  • @Rizwankhan-ts3gk
    @Rizwankhan-ts3gk ปีที่แล้ว

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

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

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

  • @SaurabhYadav008
    @SaurabhYadav008 5 หลายเดือนก่อน +1

    Hey Alisha your way of explanation is much better than striver. Bas thoda slow bola karo

  • @ankitsharda-n7b
    @ankitsharda-n7b ปีที่แล้ว

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

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

    Thank you .. yours explanation was best 😊😊❤

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

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

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

    Great sister best explanation keep it up 🔥🔥🔥🔥

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

    Best explanation!
    Hands Down.

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

    Superb explanation 👌

  • @cs-concepts2901
    @cs-concepts2901 2 ปีที่แล้ว +1

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

  • @ASHUTOSHSHARMA-us6hd
    @ASHUTOSHSHARMA-us6hd 6 หลายเดือนก่อน

    thank you for the explanation, may god bless you.

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

    Alisha is good teacher..i can easily under stand

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

    very Nice explanation....understood finally🙃

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

    You are too good at teaching ❤

  • @AmanSharma-vb5jl
    @AmanSharma-vb5jl 2 ปีที่แล้ว

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

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

    you explained it so easily , seriously thank uh

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

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

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

      Kyo big chasma pahna tha

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

    Superb Explanation 👍

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

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

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

    Really Nice Explaination

  • @Joy-ow3pt
    @Joy-ow3pt 2 ปีที่แล้ว

    you always come with good explanation

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

    Thanks for making matrix question easy 😄, great explanation

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

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

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

    COMMENTED APPROACH !!!
    void setZeroes(vector& matrix)
    {
    int rows = matrix.size();
    int cols = matrix[0].size();

    // for the first row & first col set x=1 & y=1 respectively as flag values.
    int x=1, y=1;

    //iterating first col
    for(int i=0; i

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

    great explanation alisha

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

    great Explanation....thankyou

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

    masttt smjhayaa

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

    Excellent explaination

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

    Well explained..

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

    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 😊

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

    awesome explanation, very good

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

    thank you didi wonderful explanation

  • @ALOKKUMAR-sg5nb
    @ALOKKUMAR-sg5nb 4 หลายเดือนก่อน

    Excellent solution

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

    Best Explanation.

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

    Youre doing great job

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

    Great explanation 🛐

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

    Exceptional Explanation.

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

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

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

    Crystal clear. Again.
    Thanks

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

    much better explanation then striver

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

    Very helpful video

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

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

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

    Such an amazing approach! Thanks a ton!

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

    Thanks for such a good explanation 🙏🙏

  • @VishalKumar-hh4fw
    @VishalKumar-hh4fw 2 ปีที่แล้ว

    I loved the explaination, thank you

  • @info-tech6041
    @info-tech6041 ปีที่แล้ว

    best expalanation ever

  • @072-deepakshimahajan3
    @072-deepakshimahajan3 2 ปีที่แล้ว

    Great Explanation!!

  • @AnuragPandey-ni1lo
    @AnuragPandey-ni1lo 2 ปีที่แล้ว

    Nice Explanation :)

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

    Your English is lit❣️❣️❣️

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

    Well explained!

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

    nice explanation

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

    better then striver explanation definately :)

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

      I just came here after seeing lot of complexity in striver video. For this problem he unnecessarily complexed it.

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

    Very clear explanation!

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

    thanks for the explanation

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

    please add video of spiral matrix it will be very helpful

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

    awesome di

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

    u explained very very well!

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

    Thanks for explanation👍

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

    Thanks Alisha ♥️

  • @AmodKumar-qf1ok
    @AmodKumar-qf1ok 2 ปีที่แล้ว

    Nice🔥🔥🔥🔥

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

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

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

    Nice 💯🎉

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

    nice explanation didi

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

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

    Perfect 👌

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

    One correction, in the video not in the code:
    In video you told, first to solve the inner 3*3 matrix and after that we don't have to care of them and after that we will look into the 1st row and the first column and when we see any 0 there then mark whole row or whole column as 0.
    but I guess the order should be reversed and first we should mark in the 1st row and column, because if we solve for the inner matrix first then obviously the 1st row and column will contain 0 for sure.
    so the correction is that beforehand only we should put markers in the 1st row and column then solve the inner matrix, which you did in the code.

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

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