No video

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

  Рет қаралды 21,484

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 67
@dumbstonks
@dumbstonks Ай бұрын
You explained the optimized part in the best way from all the videos on youtube, thanks!
@bhavyaagrawal7098
@bhavyaagrawal7098 2 ай бұрын
finally understood the last method 😭 it took my day while learning from striver
@nikoo28
@nikoo28 2 ай бұрын
Glad it helped!
@mondeepchetry3095
@mondeepchetry3095 2 ай бұрын
literally, i was having a hard time learning the optimal solution from striver, that shit was like some rocket science to understand.
@nikoo28
@nikoo28 24 күн бұрын
everyone has a different style of explaining. Sometimes striver might click better for you...other days it could be mine :)
@Tapadar.Monsur
@Tapadar.Monsur Жыл бұрын
Please continue with more array questions. Your explanation is top notch.
@tanveerabbas26
@tanveerabbas26 Жыл бұрын
that is the only video where I could understand intuition
@baksonyan4ik
@baksonyan4ik 11 ай бұрын
Я скачал 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 ай бұрын
Да, рассмотрение проблемы с помощью визуальных эффектов очень помогает. Я так рад, что это было полезно для вас.
@unknownman1
@unknownman1 7 ай бұрын
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 ай бұрын
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.
@amanverma8258
@amanverma8258 Жыл бұрын
Wonderful explanation! Finally got it, sir
@palspal2329
@palspal2329 Жыл бұрын
Only you were able to explain it clearly for me, thanks brother
@nikoo28
@nikoo28 Жыл бұрын
so happy to hear that.. :)
@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
@nikhilagrawal9217
@nikhilagrawal9217 2 ай бұрын
Very clear explanation!!. Thanks a lot.
@codingwave56
@codingwave56 5 ай бұрын
Thanks Helpful!
@NITISHKUMAR-ng4pu
@NITISHKUMAR-ng4pu 2 ай бұрын
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
@jedex99
@jedex99 11 ай бұрын
we are with u sir thanks for make it so much easy soln
@parthanuj8611
@parthanuj8611 Жыл бұрын
kya baat hai sir maja aa gaya . loved this
@ElectronaMusic
@ElectronaMusic 14 күн бұрын
thanks!
@pratyakshamaheshwari8269
@pratyakshamaheshwari8269 Жыл бұрын
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 ??
@sachinsoma5757
@sachinsoma5757 11 ай бұрын
The only part I was confused is the for(int i = 1;i
@nikoo28
@nikoo28 11 ай бұрын
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
@SadhanaSharma
@SadhanaSharma 11 ай бұрын
Thank you sir... this is just an amazing approach
@Honest_View
@Honest_View Ай бұрын
Sir, Why we are using Matrix[0].length & Matrix.length in some for loops? What is the difference between them
@abhijnasankesha5182
@abhijnasankesha5182 9 ай бұрын
Thanks
@b_01_aditidonode43
@b_01_aditidonode43 3 ай бұрын
amazing explanation sir!!
@shravanthombre3407
@shravanthombre3407 Жыл бұрын
great explanation!!
@nikoo28
@nikoo28 Жыл бұрын
Glad you liked it!
@nikhil2373
@nikhil2373 Жыл бұрын
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?
@haripriyaveluchamy9449
@haripriyaveluchamy9449 11 ай бұрын
your explanation is too good keep rocking
@nikoo28
@nikoo28 10 ай бұрын
Thank you so much 🙂
@saurabhruikar3196
@saurabhruikar3196 Жыл бұрын
Please do upload videos regarding graph algorithms your explanation style will make it easy to understand.
@nikoo28
@nikoo28 Жыл бұрын
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: kzfaq.info/sun/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@mohitahlawat455
@mohitahlawat455 6 ай бұрын
Great sir ❤
@Dhruv_Sharma_123
@Dhruv_Sharma_123 10 ай бұрын
Thanks understood
@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 !!!!!
@curtdudeanmol9393
@curtdudeanmol9393 Жыл бұрын
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 .
@infinite639
@infinite639 Жыл бұрын
Teaching mast hai bhai aapki
@nikoo28
@nikoo28 Жыл бұрын
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 ай бұрын
The complete playlist on graphs is now available: kzfaq.info/sun/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@yomamasofat413
@yomamasofat413 14 күн бұрын
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?
@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)
@honey-xr5kp
@honey-xr5kp 5 ай бұрын
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.
@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 Ай бұрын
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
Happy birthday to you by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 11 МЛН
Мы сделали гигантские сухарики!  #большаяеда
00:44
WHO CAN RUN FASTER?
00:23
Zhong
Рет қаралды 44 МЛН
Set Matrix Zeroes | O(1) Space Approach | Brute - Better - Optimal
30:07
Set Matrix Zeroes - In-place - Leetcode 73
18:05
NeetCode
Рет қаралды 125 М.
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 93 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН