No video

Maximum Sum Rectangular Submatrix in Matrix dynamic programming/2D kadane

  Рет қаралды 203,447

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Find maximum sum rectangle in 2D matrix.
/ tusharroy25
github.com/mis...
github.com/mis...

Пікірлер: 248
@khaleja26
@khaleja26 7 жыл бұрын
2, 0, 2, -3 maximum sum using Kadence algorithm is 4
@anderson101866
@anderson101866 4 жыл бұрын
I believe it just a typo, so it should be 4. It might not be a big problem because it doesn't affect the final answer in this video.
@lakshyaagarwal2005
@lakshyaagarwal2005 4 жыл бұрын
Yes it is 4
@biswamohandwari780
@biswamohandwari780 3 жыл бұрын
to err is human
@30saransh
@30saransh 2 жыл бұрын
Pain And Suffering, replayed that section 10 times to see how TF it's 5.
@lakshaythegupta
@lakshaythegupta 2 жыл бұрын
@@30saransh 💯🤣
@Official-tk3nc
@Official-tk3nc 4 жыл бұрын
if you are watching this in lockdown you are one of the rare species on the earth . many students are wasting their time on facebook, youtube, twitter, netflix, watching movies playing pubg, but you are working hard to achieve something . ALL the best ...nitj student here
@gauravchaudhari9279
@gauravchaudhari9279 4 жыл бұрын
True. Thank you and same to you. iiit-h student here
@maythecodesbewithyou29
@maythecodesbewithyou29 4 жыл бұрын
all the best for future man
@ayushraj-zb6sv
@ayushraj-zb6sv 4 жыл бұрын
bit mesra here!
@rahulkumarchaubey4266
@rahulkumarchaubey4266 4 жыл бұрын
Nit jaipur here
@vikashkumarchaurasia1299
@vikashkumarchaurasia1299 4 жыл бұрын
NIT jsr here !!
@youngmoney1990
@youngmoney1990 9 жыл бұрын
Nice initiative dude. I'd advice you to give a proof of concept of the algorithm you are walking through, like why this would actually always work. For some algorithms its trivial but for some it's not. Its always good for the sake of completeness. Like in this example, for every column_start and column_end combination you are finding the maximum submatrix and then taking the max of all those combinations. Anyways, a really good initiative and keep up the good work.
@Cryogenics12
@Cryogenics12 8 жыл бұрын
Very well done video. Thank you for tracing steps and explaining logic without code. That's really important
@clusteringmiu
@clusteringmiu 5 жыл бұрын
omg it's 2019 and you are still contributing to the coding noobs like me! Love you~~
@rishabhratan2925
@rishabhratan2925 3 жыл бұрын
2021
@lolnoob5015
@lolnoob5015 3 жыл бұрын
I'm from the future, 2026
@alanmarkkristensen2878
@alanmarkkristensen2878 7 жыл бұрын
Beautiful! I was looking for a simple explanation, and this is by far the best i've found. Great work!
@nitin7829
@nitin7829 3 ай бұрын
Coming back to this even after 6 years of college. Big Time Nostalgia !!!
@saifurrahmanbhuiyan925
@saifurrahmanbhuiyan925 9 жыл бұрын
When, L = 0 and R = 0. isn't the max sum 4? Why is it 5?
@KrishanaKantPareek
@KrishanaKantPareek 9 жыл бұрын
***** No.
@VishalSharma-hq5ti
@VishalSharma-hq5ti 4 жыл бұрын
yes, its 4
@dumbskull5593
@dumbskull5593 4 жыл бұрын
Yea, I'm pretty sure the max sum's supposed to be 4. He might have just made a typo.
@SnapSHORT1
@SnapSHORT1 3 жыл бұрын
ignore it
@Felix-wo7qz
@Felix-wo7qz 5 ай бұрын
Very good explanation, very clear. Thank you very much 👍🏻
@nicolaswolyniec1354
@nicolaswolyniec1354 5 жыл бұрын
thanks! I was shocked at the first time for the current sum=5 instead 4, but the best explanation I found! :)
@mayur_madhwani03
@mayur_madhwani03 2 жыл бұрын
What an explanation It was so clear that I wrote code on my own
@harishkumarrayasam
@harishkumarrayasam 9 жыл бұрын
Beautifully explained. Please upload more videos... Will recommend this channel to all my friends...
@rajendrab6509
@rajendrab6509 9 жыл бұрын
Became Fan boy of Tushar Roy.. Great Explanation.
@RaviKumar-vk6ib
@RaviKumar-vk6ib 4 жыл бұрын
Thanks tushar...you are doing a wonderful job and helping the coding community a lot...big follower of your videos
@SmartProgramming
@SmartProgramming 5 жыл бұрын
perfectly explained, thanks a lot for this tutorial 👍👍👍👍🙂🙂🙂🙂
@rizz_z1380
@rizz_z1380 2 жыл бұрын
explanation was very clear and I understood the solution in one go. Thanks.
@ashishgoyal2711
@ashishgoyal2711 9 жыл бұрын
sir its amazing.... keep doing it lyk this.... thank u so much for the video
@princejohn4152
@princejohn4152 2 жыл бұрын
When understand same the algorithm from other source, then time complexity of understanding the algorithm is O(n^2). But listening your lecture on same algorith, then time complexity of understanding is reduce to O(n). 🙂🙂🙂
@jy5886
@jy5886 8 жыл бұрын
Definitely the best algo instructor!
@golamazamabbasy1565
@golamazamabbasy1565 9 жыл бұрын
loud and clear,awesome
@darshitdalal3273
@darshitdalal3273 Жыл бұрын
This is such a lovely and lucid explanation.
@ZhihongCheng
@ZhihongCheng 9 жыл бұрын
Hi brother, I am your fan! Thanks for the video!
@anyu8109
@anyu8109 8 жыл бұрын
+Zhihong Cheng Me too. He explains those algorithms so clear and easy to understand.
@sandeepvulluri8887
@sandeepvulluri8887 5 жыл бұрын
@@anyu8109 hahaha me tooo!
@abhimanyushekhawat2626
@abhimanyushekhawat2626 7 жыл бұрын
Yeah you explained it very well but a little intuitive walk through for the algorithm will be great!
@deshabhaktg6530
@deshabhaktg6530 3 жыл бұрын
Thanks for making such a great video. You made problem look really simple,.
@JAYLATHIA
@JAYLATHIA 7 жыл бұрын
Awesome explanation with traces and step-by-step process...
@sanchitjain7204
@sanchitjain7204 7 жыл бұрын
Couldn't be more easier than this. Great job mate !
@nayanjain5761
@nayanjain5761 3 жыл бұрын
Tushar Sir you are awesome.
@pramichak6762
@pramichak6762 8 жыл бұрын
The best algo teacher..
@argc
@argc 2 жыл бұрын
amazing algorithm and explanation/video. thanks!
@abdullahalnayem1849
@abdullahalnayem1849 4 жыл бұрын
Thanks brother. You really made coding simple.
@niranjanagrawal294
@niranjanagrawal294 8 жыл бұрын
Hats off to you bro, you made the dynamic programming so simple!! Loved all your videos .. thanks once again man :-)
@saifurrahmanbhuiyan925
@saifurrahmanbhuiyan925 9 жыл бұрын
the best channel for dynamic programming Bro plz continue . We r benifitted. I need Bitmask dp Thanks
@harshpanwar1550
@harshpanwar1550 3 жыл бұрын
Thanks a ton sir... U made it extremely easy to understand!!!!!!!
@vivekpatel8109
@vivekpatel8109 8 жыл бұрын
you are just awesome tushar sir... very very nice explaination
@xxmajia
@xxmajia 9 жыл бұрын
awesome explanation, but i think there is a bug in your implmentation {code} for(int i=0; i < arr.length; i++){ maxSoFar += arr[i]; if(maxSoFar < 0){ maxSoFar = 0; currentStart = i+1; } if(max < maxSoFar){ maxStart = currentStart; maxEnd = i; max = maxSoFar; } } {code} you should check if(max < maxSoFar) before if(maxSoFar < 0), just image if the whole array is negative. you will end up with 0 as the max sum which is incorrect
@anyu8109
@anyu8109 8 жыл бұрын
+陈满砚 Nice discussion.
@hennessytj24
@hennessytj24 8 жыл бұрын
Thanks for posting this video. I found it informative and easy to follow. Great job!
@user-bv6bi2sz8r
@user-bv6bi2sz8r 8 жыл бұрын
Great video, it helps me a lot! The explanation is very thorough.
@beinghumanbeing5182
@beinghumanbeing5182 3 жыл бұрын
*I think this guy is working in amazon* . Its been five years we met
@petrugurita9728
@petrugurita9728 8 жыл бұрын
Very well explained . Hats off.
@bhaskarsuthar7600
@bhaskarsuthar7600 8 жыл бұрын
Very nice explanation Tushar. Thanks for sharing.
@harshsahu7825
@harshsahu7825 4 жыл бұрын
You really made coding easy. Thanks!!
@muskangupta5873
@muskangupta5873 3 жыл бұрын
Amazing explanation sir
2 жыл бұрын
Great explanation, Thank You.
@omkarpanhalkar6837
@omkarpanhalkar6837 7 жыл бұрын
thank you Tushar... You are the best
@rituagrawal2218
@rituagrawal2218 8 жыл бұрын
As usual; awesome explaination . Thanks Tushar
@akshayjagtap595
@akshayjagtap595 2 жыл бұрын
This is a good initiative. But I find your videos focused on going through the procedure rather than explaining how one should approach the problem.
@KirubaEbenezer
@KirubaEbenezer 8 жыл бұрын
@2:35 I can't understand how the current sum = 5....
@khaledismail
@khaledismail 8 жыл бұрын
the current sum is 4 not 5
@imrajya
@imrajya 7 жыл бұрын
He made a small mistake. He has corrected the mistake by putting a caption "Sum is 4 not 5".(This mistake is repeated at 1 more place and corrected by putting the caption). Otherwise the solution and explanation are great.
@mu3076
@mu3076 5 жыл бұрын
He made a mistake,, it is 4
@himanshu222222
@himanshu222222 9 жыл бұрын
thanks a lot sir,.......the explanation is perfect .... thank u .......
@banaaboy6504
@banaaboy6504 3 жыл бұрын
Five Stars!!! Thanks from Russia! ))))
@JaySolanki91
@JaySolanki91 5 жыл бұрын
This is a really awesome approach!
@studyaccount794
@studyaccount794 2 жыл бұрын
Please tell the explanation why we are going to use dynamic programming. In some problems like lcs and others it's obvious that there was a recursion and we had to optimize that but this problem is different.
@akashmishra5630
@akashmishra5630 9 жыл бұрын
Respect for such nice efforts..
@vicky501513
@vicky501513 9 жыл бұрын
Thanku Sir.. Amazing explanation..
@AlokGuptakumar
@AlokGuptakumar 6 жыл бұрын
ignore two errors...video is awesome
@Hameddelavar99
@Hameddelavar99 Жыл бұрын
I appreciate about this understandable video
@clyt9636
@clyt9636 9 жыл бұрын
great explanation Tushar! But can you explain how you come up with the algorithm. The intuitions that guide you towards this approach.
@shyampatil8399
@shyampatil8399 7 жыл бұрын
This is a great help Tushar. Thanks a lot!
@saumya1857
@saumya1857 8 жыл бұрын
you made the dynamic programming so simple, thank you :)
@MOHDSALMAN-sj2zu
@MOHDSALMAN-sj2zu 8 жыл бұрын
I found this link on geeksforgeeks, u explained this algorithm much better than geeks , it really helped me to understand what actually is going on. Will u plz make more videos of some difficult article which r on geeksforgeeks
@abhishekjaiswal6492
@abhishekjaiswal6492 3 жыл бұрын
straightforward solution
@darkprince2703
@darkprince2703 Жыл бұрын
The video was really good but the answer for the first iteration curr_sum is 4
@dyrpa546
@dyrpa546 6 жыл бұрын
I don't know why the time cost of creating a temporary array for sums of rows is "row". For creating it , we should get sum for each row, it will cost [Right - Left](get sum of a row)*Row(how many row we have). In this way , it's seems unreasonable that the time cost is only "row". I'm very confusing , who can tell me why?
@shubhamsingh-nt9mm
@shubhamsingh-nt9mm 6 жыл бұрын
we could'nt ask for more..excellent explaination ..thanks alot,we hope u upload videos on other topics..i know dp is ur fav :P
@shilinwang2958
@shilinwang2958 3 жыл бұрын
NICE explanation
@bogdanrizescu8271
@bogdanrizescu8271 5 жыл бұрын
Well done, Tushar! :D
@srikanthvelpuri2973
@srikanthvelpuri2973 2 жыл бұрын
Good Explanation
@sadmanahmmed2214
@sadmanahmmed2214 8 жыл бұрын
your all vdos r awesome
@aseemchakrabarthy9455
@aseemchakrabarthy9455 8 жыл бұрын
Really helpful !! Nice explanation ...Thankyou
@Lisa-kk6go
@Lisa-kk6go 6 жыл бұрын
Why do we only apply kadane to cols instead of both cols and rows? It seems that we are only adding numbers when we move L and R.
@TheDon640
@TheDon640 7 жыл бұрын
Thankyou Sir you are doing fabulous job ...But don't you think we have to repeat same algo row by row also and then compare these two (colum vs row) which submatrix has maximum cost..Because i have done this with row operation and got max_cost=27..
@Sonakshi111
@Sonakshi111 7 жыл бұрын
Hi Tushar. Can you post a video on " Max Sum of Rectangle No Larger Than K"? It's somewhat similar but has a different trick to calculate the sum in the end.
@iskariotas
@iskariotas 7 жыл бұрын
I think that you could just write another condition: "Increment R, if L + R
@true_human_007
@true_human_007 5 жыл бұрын
This solution does not work. You are restricting the use of all column by the solution. Most of the case, we will not reach to last column. We don't have to limit the sum of complete column to K. Complete sum of column is not required. Partial sum of column would be fine when satisfying our logic. This means our result rectangle may have side = length of input matrix.
@saifurrahmanbhuiyan925
@saifurrahmanbhuiyan925 9 жыл бұрын
The dynamic programming which works with bitwise operation , is called bitmask dp
@kuralamuthankathirvelan
@kuralamuthankathirvelan 5 жыл бұрын
Tushar roy fans hit like !❤
@Komachka92
@Komachka92 8 жыл бұрын
It is so perfect explanation! Thank you very much!!
@TheParvMudgil
@TheParvMudgil 4 жыл бұрын
How is 2 + 2 = 5 if its perfect? Refer - 02:28
@jonathanhoyos8191
@jonathanhoyos8191 9 жыл бұрын
Thanx a lot!!! I really appreciate you to do this
@ErfanHossainShoaib
@ErfanHossainShoaib 9 жыл бұрын
Please add a video for sub squire matrix max sum. Thanks for your best effort .......
@apoorvchaturvedi6614
@apoorvchaturvedi6614 9 жыл бұрын
Another nice explanation....:)
@shekhataul5736
@shekhataul5736 4 жыл бұрын
Awesome tutorial, very thanks.
@Raj-ev8um
@Raj-ev8um 8 жыл бұрын
thanks for the video Tushar...! if the size of sub-matrix is already given then what can be the best approach to solve this problem. ( i think naive approach will cost n^4 ).
@vin0summers
@vin0summers 9 жыл бұрын
Amazing description!
@algorithmimplementer415
@algorithmimplementer415 4 жыл бұрын
You are a genius!!
@durgeshdeep2544
@durgeshdeep2544 9 жыл бұрын
Thanks Tushar !!
@sidhantkushwaha2766
@sidhantkushwaha2766 6 жыл бұрын
Excellent explanation.
@rajcodingworld7768
@rajcodingworld7768 8 жыл бұрын
I understood the mechanics of it but not the intuition behind it.. how it's giving max values if we follow that process.. I appreciate if you can explain - Raj
@yernartalgatuly4252
@yernartalgatuly4252 8 жыл бұрын
Thanks for explanation. I have a question. at 2:36. Why your currentSum is 5? It should be 4
@yernartalgatuly4252
@yernartalgatuly4252 8 жыл бұрын
+Tushar Roy Ok. It doesn't matter. But I undertood this algorithm by your video. Thanks
@SonuSonu-tk5pk
@SonuSonu-tk5pk 7 жыл бұрын
zabardast samjhate hai aap sir ji
@SergeyAngelov
@SergeyAngelov 5 жыл бұрын
Great explanation!
@rajatsran5213
@rajatsran5213 4 жыл бұрын
thanks bro nice explanation
@HimanshukhantwalDeveloper
@HimanshukhantwalDeveloper 8 жыл бұрын
easy explanation.. thanks for the help..
@pleasantdayNwisdom
@pleasantdayNwisdom Жыл бұрын
4:15 Why not Max down as 3 since maximum subsequence sum so 3 6 0 0 total 9
@bhagwatkumarsingh2820
@bhagwatkumarsingh2820 8 жыл бұрын
Hi Tushar , It was a great help from your tutorial . I understand the logic so cool that I was able to write the code in one go.
@lucastian6027
@lucastian6027 3 жыл бұрын
No one is doubting the time complexity? After you got the column sums stored at the buffer with size = row, you will need (row * row) time to find the maximum sum. So the time complexity should be col * col * row * row
@jamesqiu6715
@jamesqiu6715 7 жыл бұрын
Looks OK... even with minor errors... but what is the heart of this algorithm? What's the DP nature in this question?
@JoanFFF
@JoanFFF 4 жыл бұрын
bro you are so good
@nihalsrivastava
@nihalsrivastava 8 жыл бұрын
Awesome.
@bruce160280
@bruce160280 8 жыл бұрын
Nice explanation man
@517-geethaannapareddy8
@517-geethaannapareddy8 Жыл бұрын
Clearly explained
@afsarabc
@afsarabc 7 жыл бұрын
EExcellent Explanation.Thanks
@carmenelenabruma4977
@carmenelenabruma4977 Жыл бұрын
I need to know how to adjust the values of maxUp and maxDown in C++ code. 🤔💻 Thank you!
@rishuinindia
@rishuinindia 8 жыл бұрын
That was perfect !
@TheParvMudgil
@TheParvMudgil 4 жыл бұрын
How is 2 + 2 = 5 if its perfect? Refer - 02:28
Egg Dropping Dynamic Programming
11:17
Tushar Roy - Coding Made Simple
Рет қаралды 199 М.
The Joker kisses Harley Quinn underwater!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 39 МЛН
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 20 МЛН
طردت النملة من المنزل😡 ماذا فعل؟🥲
00:25
Cool Tool SHORTS Arabic
Рет қаралды 32 МЛН
这三姐弟太会藏了!#小丑#天使#路飞#家庭#搞笑
00:24
家庭搞笑日记
Рет қаралды 118 МЛН
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,1 МЛН
Sum Query in 2D Immutable Array Dynamic Programming
18:34
Tushar Roy - Coding Made Simple
Рет қаралды 50 М.
Burst Balloon Dynamic Programming[Leetcode]
27:22
Tushar Roy - Coding Made Simple
Рет қаралды 103 М.
Maximum Sum Increasing Subsequence Dynamic Programming
8:30
Tushar Roy - Coding Made Simple
Рет қаралды 81 М.
Knuth-Morris-Pratt(KMP) Pattern Matching(Substring search)
12:50
Tushar Roy - Coding Made Simple
Рет қаралды 1,1 МЛН
The Joker kisses Harley Quinn underwater!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 39 МЛН