Set Matrix Zeroes | O(1) Space Approach | Brute - Better - Optimal
Вставка
- Опубліковано 15 лип 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: ua-cam.com/video/N0MgLvceX7M/v-deo.html
bhaiya same hi to dono hai
Mind got blown away after listening to the optimal solution
😂😂
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.
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.
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.
this is the only study related playlist which im binging by choice and loving it
Understood. Happy that I came up with the better approach by myself, seriously blown away by the optimal approach. Thank you so much Striver
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🙂
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 ❤
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 ?
Your teaching skills are very well and I must say they are on another level. Thank you so much for the content.
Understood! Amazing explanation as always, thank you very much for your effort!!
So desperately trying this question for 2 days wasn’t able to optimise it, Now I can❤🔥
along with i really learn how to write clean code & improve readability !! thanks striver
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++
super bro, i got 1st approach and was scratching my head to optimize it , watched last method twice now i understood🤩
U r a legend bro i am impressed by your problem solving skills
You are my motivation to solve the dsa problems every day. Thanks for providing these videos, it helps a lot🔥
great brother!!
just can't imagine the optimizations you made
hats off sirr!!
Understood and it's Amazing How you teach.
Great explanation Raj. Thanks for creating this videos. Keep making videos like this. I have just started your SDE sheet for learning DSA
watched the video thrice to finally get optimal approach to my head.
thankyou for the efforts🤗🤗🤗
Literally Awesome Explanation , easiest way
Understood, very clearly explained
Beautiful explanation!
You are the soul and heart of DSA.
OMG !!! Awesome explanation.. Thanks Striver
Your consistency is admirable @Striver
All videos are very helpful ❤️
Very good algorithm .... the optimal one is really good. Thanks a lot, sir!
Crystal Clear Explanation!
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...
thank you so much for such a great effort.
Understood,Thank you striver for this amazing video.
best explaination ,just love it!!
Great optimisation 🔥
Gained some Brain Cells After doing the Optimized, Still getting in my head, Damn Solution 🤯🤯
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.
just blew my mind, The OP optimal approach 🤯🚀
Thank you for providing such good content
Understood , great explanation
watched your video ...then others video...then again your video ...then finally understood it😇😇
Thank you so much🥰
Very much helpful !!
Understood after going through twice
❤❤
Best explanation
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.
AMAZING SIR , UNDERSTOOD VERY WELL
Thank you sir you're great.
thanks for this explanation
understood everything
Understood sir, very great explanation. I was very excited in the 7th minute itself. 🔥🔥🔥
7 7 7 7 7 7 !!!!
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.
Understood very well
crystal clear approach
inspired by you and making videos like you!
Such a great solution ✨
Thank you Bhaiyaa!❤
❤
Understood. Thanks a lot
NEXT LEVEL man 😍😍🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥loved your videos
Understood. Thank you bro
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.
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🗣️ 🔥🔥
Superb Explaination
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 :)
wow mindblown amazing understood bro
understood thank you so much bro
Understood bhaiya, thank you
You just added one more #fan in your infinte length array ❤
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! ❤
Loved ❤ ...
Understood
Thank you so much bhaiya ❤️❤️❤️❤️
Amazing Bhaiya !
First code in spreadsheet and got some feel🥵😱❣❣
just awesome ♥
Awesome 👍
understood striver
Thanks
Understood, thanks :)
SDE Sheet: Day 1 Problem 1 Done!
Thank you very very very very much sir
good approach👏👏👏
Understood✅🔥🔥
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;
}
}
}
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
Love you so much bro
Thanks 🙏
Thankyou. Bhai for videos 😶
Understood !
Understood🔥
Understood!!! 🔥🐢
thank you sir❣
jai jinendra sir understood
Understood Sir💗🙏
Understood ❤
Understood Sir!
Understood!!🙇♂
Understood🙌🙌🙌🙌
Understood👍🏻
tysm sir
Understood sir🤩
Thank you