Set Matrix Zeroes (LeetCode 73) | Full solution 3 different ways with diagrams and visuals

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

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

  • @dumbstonks
    @dumbstonks 29 วันที่ผ่านมา +3

    You explained the optimized part in the best way from all the videos on youtube, thanks!

  • @bhavyaagrawal7098
    @bhavyaagrawal7098 2 หลายเดือนก่อน +6

    finally understood the last method 😭 it took my day while learning from striver

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

      Glad it helped!

    • @mondeepchetry3095
      @mondeepchetry3095 2 หลายเดือนก่อน +3

      literally, i was having a hard time learning the optimal solution from striver, that shit was like some rocket science to understand.

    • @nikoo28
      @nikoo28  21 วันที่ผ่านมา +5

      everyone has a different style of explaining. Sometimes striver might click better for you...other days it could be mine :)

  • @Tapadar.Monsur
    @Tapadar.Monsur ปีที่แล้ว +10

    Please continue with more array questions. Your explanation is top notch.

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

    that is the only video where I could understand intuition

  • @baksonyan4ik
    @baksonyan4ik 11 หลายเดือนก่อน +1

    Я скачал leetcode Torture (расширение для гугла), после чего там далась эта задача, которую я не мог решить в течении часа, (потому что я не когда не заходил на leetcode) но вы обьяснили эту задачу так быстро и проффесионально. Большое спасибо!
    I downloaded the Leetcode Torture extension, and then I got this stupid problem that I was struggling with, like, for an hour, but you've solved it in just 20 minutes, and that quickly and professionally... with explained every step of the process. Thank you very much

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน +1

      Да, рассмотрение проблемы с помощью визуальных эффектов очень помогает. Я так рад, что это было полезно для вас.

  • @unknownman1
    @unknownman1 7 หลายเดือนก่อน +1

    I really like how you've arranged the videos in your playlist. The upcoming videos are somewhat related to the concepts learned in the previous lessons. Thanks!

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

      Glad you like them!

  • @sachinsoma5757
    @sachinsoma5757 11 หลายเดือนก่อน +1

    You are a great teacher. That was the best explanation I found so far. Keep teaching.

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

      Thank you, I will

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

    Amazing explanation, got the understanding of firstRow and firstCol when I got stuck with the leetcode example where there is only a single 0 in middle of the matrix.
    Thanks.

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

    Only you were able to explain it clearly for me, thanks brother

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

      so happy to hear that.. :)

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

    Wonderful explanation! Finally got it, sir

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

    Another solution without using extra space
    Start row wise first. Select rows one by one and make all the elements of that row -1 except which are 0, if any element in that row is 0. Similariy you have to do the same thing for columns.
    Now, before returning traverse the matrix and make all the -1 elements 0.
    public class Solution {
    public int[][] solve(int[][] A) {
    int n = A.length, m = A[0].length;
    for(int i = 0; i < n; i++){
    int flag = 0;
    for(int j = 0; j < m; j++){
    if(A[i][j]==0)flag = 1;
    }
    if(flag == 1){
    for(int j = 0; j < m; j++){
    if(A[i][j] != 0) A[i][j] = -1;
    }
    }
    }
    for(int j = 0; j < m; j++){
    int flag = 0;
    for(int i = 0; i < n; i++){
    if(A[i][j]==0)flag = 1;
    }
    if(flag == 1){
    for(int i = 0; i < n; i++){
    if(A[i][j] != 0) A[i][j] = -1;
    }
    }
    }
    for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
    if(A[i][j] == -1)A[i][j] = 0;
    }
    }
    return A;
    }
    }

    • @GaganSingh-zz9el
      @GaganSingh-zz9el 8 หลายเดือนก่อน

      marking them -1 doesnot increase time complexity ??

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

    finally after watching many lecture your video is recommended and it's very helpful and clear my concept

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

    please upload all dsa question , your explaination is best sir

  • @sachinsoma5757
    @sachinsoma5757 11 หลายเดือนก่อน +1

    The only part I was confused is the
    for(int i = 1;i

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน +3

      We only start from i=0 and j=0 for the first for loop, that is when you are setting the markers. After that if you observe the second for loop, we are starting from i=1 and j=1.
      If you go through the explanation again, we do this so we can use the first row and column to see if there is a zero anywhere in the respective row/column.
      Hope this helps.

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

      @@nikoo28 Thanks, understood

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

    Very clear explanation!!. Thanks a lot.

  • @NITISHKUMAR-ng4pu
    @NITISHKUMAR-ng4pu 2 หลายเดือนก่อน +1

    if there is no row or column that has 0 in it and we updated 0 in it from another element then how can we use 1st row and column to make change in whole row and column

  • @ElectronaMusic
    @ElectronaMusic 11 วันที่ผ่านมา

    thanks!

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

    Thanks Helpful!

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

    this gives incorrect Answer for this result matrix : [[1],[0],[3]] expected : [[0],[0],[0]] output: [[0],[0],[3]] --> this is in leet code , code which I wrote is below , let me know where I made mistake
    boolean firstRow = false, firstCol = false;
    // Set markers in first row and first column
    for(int i=0; i

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

      try adding print statements in your code to debug, you will then be able to see the state of your matrix at certain stages. That should help to figure out

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

      @@nikoo28 thanks for the reply, figured out the mistake, while checking for 1st column have been comparing I==0 , hence giving wrong answer .

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

    kya baat hai sir maja aa gaya . loved this

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

    we are with u sir thanks for make it so much easy soln

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

    amazing explanation sir!!

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

    Thank you sir... this is just an amazing approach

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

    Very good explanation, please used to upload frequently, or if you have any community discord or other please tell us

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

      I don’t have a discord yet…but can explore about it. Can you tell me its advantages and how it will be helpful to my viewers?

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

    Please do upload videos regarding graph
    algorithms your explanation style will make it easy to understand.

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

      Sure…I am prepping up some material for it. Graphs are a little tricky…so need a little extra time to simplify them.

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

      @@nikoo28 I have a doubt. It is for sure that we can't use the nested loop to iterate but while marking for zeros we have used a nested loop can u please solve my doubt.

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

      @@fffooccc9801 you will have to iterate over each element in the matrix atleast once, and it cannot be done without a nested loop.
      It is the levels of nesting that you want to reduce…you should only have one nested loop..not more than that.

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

      The complete playlist on graphs is now available: th-cam.com/play/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn.html

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

    your explanation is too good keep rocking

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

      Thank you so much 🙂

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

    great explanation!!

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

      Glad you liked it!

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

    Thanks

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

    Sir, Why we are using Matrix[0].length & Matrix.length in some for loops?
    What is the difference between them

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

    Great sir ❤

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

    Thanks understood

  • @yomamasofat413
    @yomamasofat413 12 วันที่ผ่านมา

    after doing so many leetcode questions like these, sometimes I feel like programming is all these hacks and tricks to make things more efficient. Anybody feels the same way?

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

    sorry have a question, why is this a constant space solution where there are nested loops multiple times? thanks so much

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

      just using loops does not mean extra space. You are said to be taking extra space when you are using extra memory equivalent to your input size.

  • @JohnSmith-uu5gp
    @JohnSmith-uu5gp ปีที่แล้ว

    Great !!!!!

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

    Teaching mast hai bhai aapki

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

      Let me what other type of questions/topics you want to see.

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

      @@nikoo28 Please make on Arraylist and linkedlist questions
      And
      Graphs, dynamic programming, hashset , hashmap

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

      @@nikoo28 i will send you the questions one by one

    • @nikoo28
      @nikoo28  6 หลายเดือนก่อน +1

      The complete playlist on graphs is now available: th-cam.com/play/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn.html

  • @honey-xr5kp
    @honey-xr5kp 4 หลายเดือนก่อน +1

    wow i really dont like matrix problems. the best solution uses 2 nested for loops and 2 more for loops

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

      Yes, matrix problems are very wonky.

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

    even in the second and third solution Time complexity is M*N , cant we reduce the time complexity to M+N ??

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

      that will not be possible, because in the worst case you will have to convert all elements to 0. which means going over each element, and that is O(m * n)

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

    The solution is wrong. Also why did you convert all the remaining elements to zero in the last step? If you take the example from striver's video he particularly said about that element.

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

      what do you mean when you say the solution is wrong? The solution passes all the given test cases on LeetCode.

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

      but sir's video is earlier than his 😅😅

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

    Thanks