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.
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.
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 ❤
Wonderful approach. Thank you soo much for putting so much efforts and helping us learn these algorithms. No words are enough to express how much your efforts mean to us🙏
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.....
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 ❤
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.
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++
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🙂
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...
After following your videos, I'm able to understand the problems on my own and even come up with optimal solutions myself. Thanks for the amazing videos.
thankjs a lot bro I've watched lots of paid videoes and after that i came here to this master piece playlist I have no words how much it helps me to crack a job guys do not buy any DSA courses just watch all the videoes it will be enough to crack any DSA interview🤗🥰🥰🥰🥰🥰🥰
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!!!!
im going with your sheet, but this question is of 2D arrays which is a bit challenge for me as i didt did any of 2 D questions yet should have given a intro before 2D questions
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
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.
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! ❤
Hi Striver, I the last approach can also be written as below which looks less complex and easy to understand int n = matrix.size(); int m = matrix[0].size(); int col0 = 1; for(int i=0; i=1; j--){ if(matrix[0][j] == 0 || matrix[i][0]==0){ matrix[i][j] = 0; } } if(col0 == 0){ matrix[i][0] = 0; } }
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; } } }
Bhaiya like in brute force approach we are converting elements to -1 suppose -1 is already present in the arrray then it will modify the matrix and that we won't want.
The bruteforce approach code provided would fail for the testcase [[-1],[2],[3]] on Leetcode. Here is modified code for BruteForce class Solution { public void setZeroes(int[][] matrix) { int m = matrix.length; int n = matrix[0].length; int[] rows = new int[m]; int[] cols = new int[n]; // Mark rows and columns that contain zeros for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (matrix[i][j] == 0) { rows[i] = 1; // Mark the row cols[j] = 1; // Mark the column } } } // Set zeros based on the marked rows and columns for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (rows[i] == 1 || cols[j] == 1) { matrix[i][j] = 0; } } } } }
Bhai kya explanation hai ekdam next level. actually bhai videos mai aap c++ ka code lekhtai ho and Mai aur mare hostel friends ham Java mai code karte hain isleye thoda uncomfortable lagta hai . Aap ke article me jata hu to purana code milta hai . please Bro add Java code in to videos it will be beneficial to lot of students otherwise this course will be end and we are the java people will unable to to follow.Please bro🙏🙏🙏 .
STRONG SUGGESTION for ease of understanding: In the better/optimal solution instead of doing the second iteration over the entire matrix just iterate over the rows and cols marked for 0-conversion (except the first row/col) and convert the elements to 0. In optimal just keep two separate variables like row0 and col0 and convert the first row/col at the very end (after all the other row/cols) are processed.
What if we do this? - use first row of matrix from 1 to m to mark columns use first column of matrix from 1 to n to mark rows keep two flags to check is first column or first row have a zero for(i=1;i set first row 0
Because since it is an integer matrix What if the matrix elements in the beginning is -1 then how can you use this approach of marking with -1 think about it .
Nice explanation of all the approaches however one feedback I have is at 14:35 video time there is some correction instead of saying minimizing space complexity you said minimizing time complexity. Thank You !!!
Please watch our new video on the same topic: ruclips.net/video/N0MgLvceX7M/видео.html
bhaiya same hi to dono hai
Mind got blown away after listening to the optimal solution
😂😂
Let's march ahead, and create an unmatchable DSA course! ❤
Use the problem links in the description.
mind got blown with the optimal approach
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.
I was able to do the second approach by myself and I'm feeling really good about it!
HOLY S... bruh is an einstein for sure
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.
i am the only dumb then because i cant do anything
@@Carson00_11 yes XD
@@Carson00_11never say something negative about yourself even as a joke
This optimal approach is confusing.
Watch again easy it is 😊
Understood. Happy that I came up with the better approach by myself, seriously blown away by the optimal approach. Thank you so much Striver
mind got blown away after listening to the optimal solution
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 ❤
Can you please share the older video link ?
Wonderful approach. Thank you soo much for putting so much efforts and helping us learn these algorithms. No words are enough to express how much your efforts mean to us🙏
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.....
this is the only study related playlist which im binging by choice and loving it
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 ❤
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.
So desperately trying this question for 2 days wasn’t able to optimise it, Now I can❤🔥
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++
Gained some Brain Cells After doing the Optimized, Still getting in my head, Damn Solution 🤯🤯
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🙂
Your teaching skills are very well and I must say they are on another level. Thank you so much for the content.
I have a seen a ad full for u bhai thanks
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...
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
Optimal approach was quite tedious to understand, however , I got it after writing down the code again myself
Yes that is the reason I went slow and long, but writing it yourself helps to clear so many things.
Understood sir, very great explanation. I was very excited in the 7th minute itself. 🔥🔥🔥
7 7 7 7 7 7 !!!!
After following your videos, I'm able to understand the problems on my own and even come up with optimal solutions myself. Thanks for the amazing videos.
U r a legend bro i am impressed by your problem solving skills
thankjs a lot bro
I've watched lots of paid videoes and after that i came here to this master piece playlist
I have no words how much it helps me to crack a job
guys do not buy any DSA courses
just watch all the videoes it will be enough to crack any DSA interview🤗🥰🥰🥰🥰🥰🥰
which course you got? PW?
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!!!!
u are literally me
@@bully9858 all the best with your coding Journey :-)
@@bully9858bro is actually him🗣️ 🔥🔥
im going with your sheet, but this question is of 2D arrays which is a bit challenge for me as i didt did any of 2 D questions yet
should have given a intro before 2D questions
great brother!!
just can't imagine the optimizations you made
hats off sirr!!
along with i really learn how to write clean code & improve readability !! thanks striver
super bro, i got 1st approach and was scratching my head to optimize it , watched last method twice now i understood🤩
What an explaination man !! Optimal solution was really out of my imagination.
You are the soul and heart of DSA.
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
Yes re-rrecorded, the previous videos were for people who already knew dsa
@@takeUforward Your teaching skills are on another level :)
just blew my mind, The OP optimal approach 🤯🚀
Understood! Amazing explanation as always, thank you very much for your effort!!
Great explanation Raj. Thanks for creating this videos. Keep making videos like this. I have just started your SDE sheet for learning DSA
You are my motivation to solve the dsa problems every day. Thanks for providing these videos, it helps a lot🔥
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.
For Brute force based solution, I think we should int_min or float("-inf), instead of -1, because -1 can be entry in matrix
Exactly, even int_min can be in the array since -2^31 is the limit in question..
@@unlockyourfinance u both are right, but how to approach it then? i tried int_MIN+1 also , 191 test casepassed for the first approach
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! ❤
May god bless you striver 🙏🙏
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.
All videos are very helpful ❤️
Plz complete it in July
Ek saal pakad ke chal..
@@sw_24212 saal bhai 😂 free k cheez ki yahi dikat hoti hai
Hi Striver,
I the last approach can also be written as below which looks less complex and easy to understand
int n = matrix.size();
int m = matrix[0].size();
int col0 = 1;
for(int i=0; i=1; j--){
if(matrix[0][j] == 0 || matrix[i][0]==0){
matrix[i][j] = 0;
}
}
if(col0 == 0){
matrix[i][0] = 0;
}
}
Superb 💥
Timestamps
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
thanx
OMG !!! Awesome explanation.. Thanks Striver
watched your video ...then others video...then again your video ...then finally understood it😇😇
Your consistency is admirable @Striver
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;
}
}
}
my head hurts after watching the optimal approach
I want to complete this series so badly but then i saw he hasn't uploaded maximum videos. Please start uploading videos brother
Is it possible for tier3 college student and non it student to learn dsa
no doubt@@someshmone
it is possible.@@someshmone
Optimal is also understood after watching it 4 times by using pen paper and seeing edge case about last step
😅
Very good algorithm .... the optimal one is really good. Thanks a lot, sir!
Understood after going through twice
❤❤
Best explanation
You just added one more #fan in your infinte length array ❤
SDE Sheet: Day 1 Problem 1 Done!
Beautiful explanation!
watched the video thrice to finally get optimal approach to my head.
thankyou for the efforts🤗🤗🤗
Great optimisation 🔥
guys if you are on leetcode number is from INT_MIN(negative) to INT_MAX(positive) that is we cant take -1 for optimal therefore do it by taking 0
understood😇
in first approch if the matrix numbers range is of int then what unique value can we take?
Bhaiya like in brute force approach we are converting elements to -1 suppose -1 is already present in the arrray then it will modify the matrix and that we won't want.
Take some variable like a,n,... Instead of -1
@@EvenHeisenbergIsCertainAboutMe kind of string type variable u r telling
@@EvenHeisenbergIsCertainAboutMe but alphabets will be stored as asci value, which are again integers
#Striver rocks & #takeUforward learner rocks 🤟👍
Understood,Thank you striver for this amazing video.
Crystal Clear Explanation!
Bro i got confused to m*n and n*m matrix pls check confirm your better solution by the way mine was like storing pairs almost the same...
Understood and it's Amazing How you teach.
Understood, very clearly explained
Understood very well
The bruteforce approach code provided would fail for the testcase [[-1],[2],[3]] on Leetcode.
Here is modified code for BruteForce
class Solution {
public void setZeroes(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
int[] rows = new int[m];
int[] cols = new int[n];
// Mark rows and columns that contain zeros
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == 0) {
rows[i] = 1; // Mark the row
cols[j] = 1; // Mark the column
}
}
}
// Set zeros based on the marked rows and columns
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (rows[i] == 1 || cols[j] == 1) {
matrix[i][j] = 0;
}
}
}
}
}
in Leetcode brute force problem there is a test case having matrix value as -1 which may cause a problem while changing -1 values in the matrix
My god 😮😮. Never thought this could have 0(1) space complexity
Bhai kya explanation hai ekdam next level. actually bhai videos mai aap c++ ka code lekhtai ho and Mai aur mare hostel friends ham Java mai code karte hain isleye thoda uncomfortable lagta hai . Aap ke article me jata hu to purana code milta hai . please Bro add Java code in to videos it will be beneficial to lot of students otherwise this course will be end and we are the java people will unable to to follow.Please bro🙏🙏🙏 .
in 7 days java and python add ho jaega
@@takeUforward what if I do dsa in javascript. Does it really matters? To be honest?
Literally Awesome Explanation , easiest way
STRONG SUGGESTION for ease of understanding: In the better/optimal solution instead of doing the second iteration over the entire matrix just iterate over the rows and cols marked for 0-conversion (except the first row/col) and convert the elements to 0. In optimal just keep two separate variables like row0 and col0 and convert the first row/col at the very end (after all the other row/cols) are processed.
One of the best optimal approach
Yea bt you can't even imagine this 😭
understood✔✔
What if we do this? -
use first row of matrix from 1 to m to mark columns
use first column of matrix from 1 to n to mark rows
keep two flags to check is first column or first row have a zero
for(i=1;i set first row 0
The brute force approach will not work for integer matrix (in leetcode integer matrix is there) but it will work for binary matrix
Why?
It will work I think
Because since it is an integer matrix What if the matrix elements in the beginning is -1 then how can you use this approach of marking with -1 think about it .
@@suraj_fusion yes got it...u can place it with a value in the extreme bounds
@@sahilkhan_cs50 It should logically work didn't try it though.
best explaination ,just love it!!
thanks for this explanation
understood everything
Nice explanation of all the approaches however one feedback I have is at 14:35 video time there is some correction instead of saying minimizing space complexity you said minimizing time complexity. Thank You !!!
AMAZING SIR , UNDERSTOOD VERY WELL
Hatss off brother🙌🙌
It was a little overwhelming but I understood everything just need to implement the last technique on my own without copy pasting.
if i talk about brute force , how can i assign -1 in the matrix , because matrix can have value from -2^31
Understood✅🔥🔥
First code in spreadsheet and got some feel🥵😱❣❣
Understood ❤❤❤❤
crystal clear approach
wow mindblown amazing understood bro
for the element which are not in markRow and markCol , and that are -1 so when we go to mark them as zero we will ended up marking them also zero ????
thank you so much for such a great effort.
Such a great solution ✨
Thank you so much🥰
Very much helpful !!