Set Matrix Zeroes | O(1) Space Approach | Brute - Better - Optimal

  Рет қаралды 320,671

take U forward

take U forward

Күн бұрын

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

Пікірлер: 462
@takeUforward
@takeUforward 11 ай бұрын
Please watch our new video on the same topic: kzbin.info/www/bejne/hGGwmH-smMqLba8
@SujitKUmar-gy5xr
@SujitKUmar-gy5xr Ай бұрын
bhaiya same hi to dono hai
@saisree04
@saisree04 3 ай бұрын
Mind got blown away after listening to the optimal solution
@ranjani7896
@ranjani7896 3 ай бұрын
😂😂
@aaryakapoor8352
@aaryakapoor8352 21 күн бұрын
mind got blown with the optimal approach
@dpxy1599
@dpxy1599 9 ай бұрын
This optimal approach is confusing.
@KaifKhan-sb2yr
@KaifKhan-sb2yr 3 ай бұрын
Watch again easy it is 😊
@takeUforward
@takeUforward Жыл бұрын
Let's march ahead, and create an unmatchable DSA course! ❤ Use the problem links in the description.
@CodeBoost8375
@CodeBoost8375 Жыл бұрын
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.
@jatinsharma1595
@jatinsharma1595 7 ай бұрын
Understood. Happy that I came up with the better approach by myself, seriously blown away by the optimal approach. Thank you so much Striver
@suyashpurwar631
@suyashpurwar631 11 ай бұрын
I was able to do the second approach by myself and I'm feeling really good about it!
@RohanKumar-gy4gl
@RohanKumar-gy4gl 10 ай бұрын
HOLY S... bruh is an einstein for sure
@adityamadhav1509
@adityamadhav1509 25 күн бұрын
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.
@Carson00_11
@Carson00_11 19 күн бұрын
i am the only dumb then because i cant do anything
@jacobblack2544
@jacobblack2544 17 күн бұрын
@@Carson00_11 yes XD
@AkshanshLohan
@AkshanshLohan 3 күн бұрын
@@Carson00_11never say something negative about yourself even as a joke
@saisree04
@saisree04 3 ай бұрын
mind got blown away after listening to the optimal solution
@yugal8627
@yugal8627 Жыл бұрын
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🙂
@vivekdalal1724
@vivekdalal1724 Жыл бұрын
this is the only study related playlist which im binging by choice and loving it
@Manishgupta200
@Manishgupta200 Жыл бұрын
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 ❤
@dxan
@dxan 4 ай бұрын
Your teaching skills are very well and I must say they are on another level. Thank you so much for the content.
@unknown_fact1586
@unknown_fact1586 3 күн бұрын
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.
@devanshulpratapsingh5963
@devanshulpratapsingh5963 Жыл бұрын
So desperately trying this question for 2 days wasn’t able to optimise it, Now I can❤🔥
@josephwilliams9
@josephwilliams9 9 ай бұрын
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 ❤
@kamalakannanng4206
@kamalakannanng4206 6 ай бұрын
Can you please share the older video link ?
@shubhamagarwal1434
@shubhamagarwal1434 2 күн бұрын
#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.....
@krishsachdeva1105
@krishsachdeva1105 Жыл бұрын
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++
@cinime
@cinime Жыл бұрын
Understood! Amazing explanation as always, thank you very much for your effort!!
@Atharva_kathiyawadi
@Atharva_kathiyawadi Жыл бұрын
along with i really learn how to write clean code & improve readability !! thanks striver
@anushkachavan5065
@anushkachavan5065 3 ай бұрын
You are my motivation to solve the dsa problems every day. Thanks for providing these videos, it helps a lot🔥
@hari7110
@hari7110 6 ай бұрын
super bro, i got 1st approach and was scratching my head to optimize it , watched last method twice now i understood🤩
@NikitaSingh-kz2ii
@NikitaSingh-kz2ii Жыл бұрын
watched the video thrice to finally get optimal approach to my head. thankyou for the efforts🤗🤗🤗
@jaydeepkarena
@jaydeepkarena Жыл бұрын
Great explanation Raj. Thanks for creating this videos. Keep making videos like this. I have just started your SDE sheet for learning DSA
@hashcodez757
@hashcodez757 2 ай бұрын
great brother!! just can't imagine the optimizations you made hats off sirr!!
@krishanubiswas6869
@krishanubiswas6869 8 ай бұрын
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...
@AbhishekSingh-mh2fg
@AbhishekSingh-mh2fg 11 ай бұрын
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.
@juliechoudhary9582
@juliechoudhary9582 Жыл бұрын
Understood and it's Amazing How you teach.
@yashwairagade3677
@yashwairagade3677 4 ай бұрын
U r a legend bro i am impressed by your problem solving skills
@FooBar-lb5wf
@FooBar-lb5wf 2 ай бұрын
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.
@Akash-yr2if
@Akash-yr2if Жыл бұрын
Gained some Brain Cells After doing the Optimized, Still getting in my head, Damn Solution 🤯🤯
@sukritinarang5016
@sukritinarang5016 5 ай бұрын
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
@sunnyvlogs__
@sunnyvlogs__ Жыл бұрын
Literally Awesome Explanation , easiest way
@shivammotani
@shivammotani Жыл бұрын
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.
@rishijain9081
@rishijain9081 4 күн бұрын
What an explaination man !! Optimal solution was really out of my imagination.
@tridibeshmisra9426
@tridibeshmisra9426 5 ай бұрын
Very good algorithm .... the optimal one is really good. Thanks a lot, sir!
@AjayKumar-sx6qo
@AjayKumar-sx6qo 11 ай бұрын
OMG !!! Awesome explanation.. Thanks Striver
@RaviKumar-sn6tu
@RaviKumar-sn6tu 4 ай бұрын
watched your video ...then others video...then again your video ...then finally understood it😇😇
@surabsebait5409
@surabsebait5409 Жыл бұрын
Understood, very clearly explained
@subhambachar
@subhambachar Ай бұрын
just blew my mind, The OP optimal approach 🤯🚀
@ankitasharma3930
@ankitasharma3930 11 ай бұрын
thank you so much for such a great effort.
@jeetdesaimusic
@jeetdesaimusic 2 ай бұрын
Crystal Clear Explanation!
@CodingEnv
@CodingEnv Жыл бұрын
You are the soul and heart of DSA.
@mgnfy-view
@mgnfy-view 10 ай бұрын
Beautiful explanation!
@hareshnayak7302
@hareshnayak7302 4 ай бұрын
Understood,Thank you striver for this amazing video.
@NaveenKumar-xq6ce
@NaveenKumar-xq6ce Жыл бұрын
Your consistency is admirable @Striver
@prashantsharma7869
@prashantsharma7869 6 ай бұрын
best explaination ,just love it!!
@AyushSharma-ye1xz
@AyushSharma-ye1xz Жыл бұрын
All videos are very helpful ❤️
@sanjayv-ef6ey
@sanjayv-ef6ey 15 күн бұрын
I have a seen a ad full for u bhai thanks
@AdarshKeshari-wc2uz
@AdarshKeshari-wc2uz 2 ай бұрын
Understood after going through twice ❤❤ Best explanation
@luckydev9006
@luckydev9006 11 ай бұрын
Thank you for providing such good content
@ankush8243
@ankush8243 6 ай бұрын
Thank you so much🥰 Very much helpful !!
@rishabhkala2115
@rishabhkala2115 Жыл бұрын
thanks for this explanation understood everything
@user-yw6zj3ir8p
@user-yw6zj3ir8p 6 ай бұрын
crystal clear approach
@sakthipriya8653
@sakthipriya8653 8 ай бұрын
Understood sir, very great explanation. I was very excited in the 7th minute itself. 🔥🔥🔥
@SaifUddin-mq1gk
@SaifUddin-mq1gk 3 ай бұрын
7 7 7 7 7 7 !!!!
@RahulYadav-jk7um
@RahulYadav-jk7um 2 ай бұрын
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! ❤
@user-ik3qu5uy5e
@user-ik3qu5uy5e 5 ай бұрын
AMAZING SIR , UNDERSTOOD VERY WELL
@karanveersinghdeora5085
@karanveersinghdeora5085 Жыл бұрын
Understood very well
@prathameshhatkar1911
@prathameshhatkar1911 Жыл бұрын
Great optimisation 🔥
@rajatrathore5455
@rajatrathore5455 Жыл бұрын
Understood , great explanation
@chethanprabhu4475
@chethanprabhu4475 Жыл бұрын
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
@takeUforward
@takeUforward Жыл бұрын
Yes re-rrecorded, the previous videos were for people who already knew dsa
@vivekpatial5614
@vivekpatial5614 Жыл бұрын
​@@takeUforward Your teaching skills are on another level :)
@samuelfrank1369
@samuelfrank1369 6 ай бұрын
Understood. Thanks a lot
@shivamgurjar8979
@shivamgurjar8979 3 ай бұрын
Such a great solution ✨
@myyoutubeisthis
@myyoutubeisthis Жыл бұрын
Thank you sir you're great.
@ddevarapaga5134
@ddevarapaga5134 Ай бұрын
wow mindblown amazing understood bro
@konankikeerthi
@konankikeerthi 2 ай бұрын
Understood. Thank you bro
@tamilmukbang3789
@tamilmukbang3789 3 ай бұрын
understood thank you so much bro
@mashkoorahmad1885
@mashkoorahmad1885 Жыл бұрын
NEXT LEVEL man 😍😍🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥loved your videos
@pallavi22222
@pallavi22222 Жыл бұрын
Superb Explaination
@TheEleetcoder
@TheEleetcoder Жыл бұрын
inspired by you and making videos like you!
@palak443
@palak443 9 ай бұрын
in first approch if the matrix numbers range is of int then what unique value can we take?
@karanhaldar755
@karanhaldar755 4 ай бұрын
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🤗🥰🥰🥰🥰🥰🥰
@user-fw4kz3bb4g
@user-fw4kz3bb4g 4 ай бұрын
which course you got? PW?
@AnkitYadav-sk4nw
@AnkitYadav-sk4nw Жыл бұрын
Thank you Bhaiyaa!❤ ❤
@abdulrehmaan153
@abdulrehmaan153 Жыл бұрын
You just added one more #fan in your infinte length array ❤
@NitinKumar-wm2dg
@NitinKumar-wm2dg Жыл бұрын
Understood bhaiya, thank you
@parthtiwari8152
@parthtiwari8152 11 ай бұрын
Loved ❤ ... Understood
@smileyyyy7372
@smileyyyy7372 Ай бұрын
May god bless you striver 🙏🙏
@shloksuman8164
@shloksuman8164 Жыл бұрын
Optimal approach was quite tedious to understand, however , I got it after writing down the code again myself
@takeUforward
@takeUforward Жыл бұрын
Yes that is the reason I went slow and long, but writing it yourself helps to clear so many things.
@user-ui9fw7qj5n
@user-ui9fw7qj5n 7 ай бұрын
understood striver Thanks
@priyotoshsahaThePowerOf23
@priyotoshsahaThePowerOf23 Жыл бұрын
First code in spreadsheet and got some feel🥵😱❣❣
@prasoonmishra995
@prasoonmishra995 Жыл бұрын
Awesome 👍
@nivetha6167
@nivetha6167 Жыл бұрын
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!!!!
@bully9858
@bully9858 10 ай бұрын
u are literally me
@nivetha6167
@nivetha6167 10 ай бұрын
@@bully9858 all the best with your coding Journey :⁠-⁠)
@GOJOANDSUKUNAFAN
@GOJOANDSUKUNAFAN 2 ай бұрын
​@@bully9858bro is actually him🗣️ 🔥🔥
@satyammishra6363
@satyammishra6363 5 ай бұрын
For Brute force based solution, I think we should int_min or float("-inf), instead of -1, because -1 can be entry in matrix
@unlockyourfinance
@unlockyourfinance 3 ай бұрын
Exactly, even int_min can be in the array since -2^31 is the limit in question..
@MahaveerJanagouda
@MahaveerJanagouda 2 ай бұрын
​@@unlockyourfinance​ u both are right, but how to approach it then? i tried int_MIN+1 also , 191 test casepassed for the first approach
@rohitraj5832
@rohitraj5832 10 ай бұрын
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; } } }
@user-cz4lk8qi2q
@user-cz4lk8qi2q 5 ай бұрын
Amazing Bhaiya !
@shivamsingh-we7ek
@shivamsingh-we7ek Жыл бұрын
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 ????
@user-ui6op1zc2q
@user-ui6op1zc2q Жыл бұрын
just awesome ♥
@itsabhinav04
@itsabhinav04 Жыл бұрын
Understood, thanks :)
@poojithkumar2283
@poojithkumar2283 Жыл бұрын
good approach👏👏👏
@shivamsingh7817
@shivamsingh7817 Жыл бұрын
Thank you so much bhaiya ❤️❤️❤️❤️
@GauravJain-zo8gt
@GauravJain-zo8gt 3 ай бұрын
jai jinendra sir understood
@sreejitkar8044
@sreejitkar8044 7 күн бұрын
Hatss off brother🙌🙌
@HR-pz7ts
@HR-pz7ts Жыл бұрын
It was a little overwhelming but I understood everything just need to implement the last technique on my own without copy pasting.
@YourCodeVerse
@YourCodeVerse 9 ай бұрын
Understood✅🔥🔥
@suyashshinde2971
@suyashshinde2971 Жыл бұрын
SDE Sheet: Day 1 Problem 1 Done!
@sounaksaha1455
@sounaksaha1455 4 ай бұрын
One of the best optimal approach
@GOJOANDSUKUNAFAN
@GOJOANDSUKUNAFAN 2 ай бұрын
Yea bt you can't even imagine this 😭
@myyoutubeisthis
@myyoutubeisthis Жыл бұрын
Thank you very very very very much sir
@SunnyYadav-zv7hp
@SunnyYadav-zv7hp Жыл бұрын
Love you so much bro
@Se7ven_Plays
@Se7ven_Plays Жыл бұрын
Thankyou. Bhai for videos 😶
@creativeprojects217
@creativeprojects217 6 ай бұрын
thank you sir❣
Rotate Matrix/Image by 90 Degrees | Brute - Optimal
17:47
take U forward
Рет қаралды 189 М.
Launching the best DSA Course + Platform
36:29
take U forward
Рет қаралды 4,5 М.
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 44 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 11 МЛН
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 860 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 365 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 441 М.
Why Do Bubbles Form In Glasses Of Water?
12:33
Joe Scott
Рет қаралды 109 М.
The Last Algorithms Course You'll Need by ThePrimeagen | Preview
16:44
Frontend Masters
Рет қаралды 313 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 291 М.
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 44 МЛН