Set Matrix Zeroes | O(1) Space Approach | Brute - Better - Optimal
Vložit
- čas přidán 24. 07. 2024
- Problem Link: bit.ly/3CukQke
Notes/C++/Java/Python codes: takeuforward.org/data-structu...
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
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
Please watch our new video on the same topic: czcams.com/video/N0MgLvceX7M/video.html
bhaiya same hi to dono hai
Mind got blown away after listening to the optimal solution
😂😂
mind got blown with the optimal approach
Let's march ahead, and create an unmatchable DSA course! ❤
Use the problem links in the description.
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
This optimal approach is confusing.
Watch again easy it is 😊
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.
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
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🙂
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 ❤
So desperately trying this question for 2 days wasn’t able to optimise it, Now I can❤🔥
Understood! Amazing explanation as always, thank you very much for your effort!!
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++
Your teaching skills are very well and I must say they are on another level. Thank you so much for the content.
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 ?
Great explanation Raj. Thanks for creating this videos. Keep making videos like this. I have just started your SDE sheet for learning DSA
super bro, i got 1st approach and was scratching my head to optimize it , watched last method twice now i understood🤩
along with i really learn how to write clean code & improve readability !! thanks striver
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.
great brother!!
just can't imagine the optimizations you made
hats off sirr!!
watched the video thrice to finally get optimal approach to my head.
thankyou for the efforts🤗🤗🤗
You are my motivation to solve the dsa problems every day. Thanks for providing these videos, it helps a lot🔥
U r a legend bro i am impressed by your problem solving skills
OMG !!! Awesome explanation.. Thanks Striver
Your consistency is admirable @Striver
You are the soul and heart of DSA.
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...
Very good algorithm .... the optimal one is really good. Thanks a lot, sir!
Literally Awesome Explanation , easiest way
Understood and it's Amazing How you teach.
All videos are very helpful ❤️
Understood, very clearly explained
Beautiful explanation!
Understood sir, very great explanation. I was very excited in the 7th minute itself. 🔥🔥🔥
7 7 7 7 7 7 !!!!
Understood,Thank you striver for this amazing video.
watched your video ...then others video...then again your video ...then finally understood it😇😇
just blew my mind, The OP optimal approach 🤯🚀
Great optimisation 🔥
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.
Crystal Clear Explanation!
best explaination ,just love it!!
thank you so much for such a great effort.
Understood after going through twice
❤❤
Best explanation
Thank you for providing such good content
AMAZING SIR , UNDERSTOOD VERY WELL
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 :)
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.
Thank you so much🥰
Very much helpful !!
Gained some Brain Cells After doing the Optimized, Still getting in my head, Damn Solution 🤯🤯
Understood , great explanation
Understood very well
I have a seen a ad full for u bhai thanks
Such a great solution ✨
crystal clear approach
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
inspired by you and making videos like you!
You just added one more #fan in your infinte length array ❤
NEXT LEVEL man 😍😍🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥loved your videos
thanks for this explanation
understood everything
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.
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! ❤
Superb Explaination
Amazing Bhaiya !
Understood. Thank you bro
SDE Sheet: Day 1 Problem 1 Done!
in first approch if the matrix numbers range is of int then what unique value can we take?
Thank you Bhaiyaa!❤
❤
wow mindblown amazing understood bro
Understood. Thanks a lot
Thank you sir you're great.
Understood✅🔥🔥
Awesome 👍
First code in spreadsheet and got some feel🥵😱❣❣
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🗣️ 🔥🔥
Understood bhaiya, thank you
Loved ❤ ...
Understood
just awesome ♥
good approach👏👏👏
Understood, thanks :)
Understood !
Understood🔥
understood thank you so much bro
Understood !!
Understood!!! 🔥🐢
Understood!!🙇♂
Thankyou. Bhai for videos 😶
Thank you so much bhaiya ❤️❤️❤️❤️
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;
}
}
}
Understood Sir!
One of the best optimal approach
Yea bt you can't even imagine this 😭
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?
Understood ❤
May god bless you striver 🙏🙏
Understood🙌🙌🙌🙌
Understood sir🤩
Understood Sir💗🙏
Understood👍🏻
Love you so much bro