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

  Рет қаралды 204,615

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 248
@khaleja26
@khaleja26 8 жыл бұрын
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
@butterChickenAndNaan98
@butterChickenAndNaan98 2 жыл бұрын
Pain And Suffering, replayed that section 10 times to see how TF it's 5.
@lakshaythegupta
@lakshaythegupta 2 жыл бұрын
@@butterChickenAndNaan98 💯🤣
@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 !!
@nitin7829
@nitin7829 5 ай бұрын
Coming back to this even after 6 years of college. Big Time Nostalgia !!!
@Cryogenics12
@Cryogenics12 8 жыл бұрын
Very well done video. Thank you for tracing steps and explaining logic without code. That's really important
@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.
@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!
@rajendrab6509
@rajendrab6509 9 жыл бұрын
Became Fan boy of Tushar Roy.. Great Explanation.
@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...
@nicolaswolyniec1354
@nicolaswolyniec1354 6 жыл бұрын
thanks! I was shocked at the first time for the current sum=5 instead 4, but the best explanation I found! :)
@darshitdalal3273
@darshitdalal3273 Жыл бұрын
This is such a lovely and lucid 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
@Felix-wo7qz
@Felix-wo7qz 7 ай бұрын
Very good explanation, very clear. Thank you very much 👍🏻
@rizz_z1380
@rizz_z1380 3 жыл бұрын
explanation was very clear and I understood the solution in one go. Thanks.
@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!
@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...
@abhimanyushekhawat2626
@abhimanyushekhawat2626 7 жыл бұрын
Yeah you explained it very well but a little intuitive walk through for the algorithm will be great!
@SmartProgramming
@SmartProgramming 6 жыл бұрын
perfectly explained, thanks a lot for this tutorial 👍👍👍👍🙂🙂🙂🙂
@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!
@abdullahalnayem1849
@abdullahalnayem1849 4 жыл бұрын
Thanks brother. You really made coding simple.
@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.
@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.
@saifurrahmanbhuiyan925
@saifurrahmanbhuiyan925 9 жыл бұрын
the best channel for dynamic programming Bro plz continue . We r benifitted. I need Bitmask dp Thanks
@vivekpatel8109
@vivekpatel8109 8 жыл бұрын
you are just awesome tushar sir... very very nice explaination
@AlokGuptakumar
@AlokGuptakumar 6 жыл бұрын
ignore two errors...video is awesome
@pramichak6762
@pramichak6762 8 жыл бұрын
The best algo teacher..
@niranjanagrawal294
@niranjanagrawal294 8 жыл бұрын
Hats off to you bro, you made the dynamic programming so simple!! Loved all your videos .. thanks once again man :-)
@ashishgoyal2711
@ashishgoyal2711 9 жыл бұрын
sir its amazing.... keep doing it lyk this.... thank u so much for the video
@bhaskarsuthar7600
@bhaskarsuthar7600 8 жыл бұрын
Very nice explanation Tushar. Thanks for sharing.
@darkprince2703
@darkprince2703 Жыл бұрын
The video was really good but the answer for the first iteration curr_sum is 4
@harshpanwar1550
@harshpanwar1550 3 жыл бұрын
Thanks a ton sir... U made it extremely easy to understand!!!!!!!
@sanchitjain7204
@sanchitjain7204 7 жыл бұрын
Couldn't be more easier than this. Great job mate !
@petrugurita9728
@petrugurita9728 8 жыл бұрын
Very well explained . Hats off.
@argc
@argc 2 жыл бұрын
amazing algorithm and explanation/video. thanks!
@beinghumanbeing5182
@beinghumanbeing5182 4 жыл бұрын
*I think this guy is working in amazon* . Its been five years we met
@rituagrawal2218
@rituagrawal2218 8 жыл бұрын
As usual; awesome explaination . Thanks Tushar
@harshsahu7825
@harshsahu7825 4 жыл бұрын
You really made coding easy. Thanks!!
@nayanjain5761
@nayanjain5761 3 жыл бұрын
Tushar Sir you are awesome.
@hennessytj24
@hennessytj24 8 жыл бұрын
Thanks for posting this video. I found it informative and easy to follow. Great job!
@程龙-b1w
@程龙-b1w 8 жыл бұрын
Great video, it helps me a lot! The explanation is very thorough.
@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
@bhagwatkumarsingh2820
@bhagwatkumarsingh2820 9 жыл бұрын
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
@golamazamabbasy1565
@golamazamabbasy1565 9 жыл бұрын
loud and clear,awesome
@akashmishra5630
@akashmishra5630 9 жыл бұрын
Respect for such nice efforts..
@muskangupta5873
@muskangupta5873 3 жыл бұрын
Amazing explanation sir
@jaikrishnan4249
@jaikrishnan4249 9 жыл бұрын
at 11.22 current sum is 8 not 7..small mistake..but the explanation was excellent....
@saumya1857
@saumya1857 8 жыл бұрын
you made the dynamic programming so simple, thank you :)
@JaySolanki91
@JaySolanki91 5 жыл бұрын
This is a really awesome approach!
@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.
@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.
@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
@omkarpanhalkar6837
@omkarpanhalkar6837 8 жыл бұрын
thank you Tushar... You are the best
@himanshu222222
@himanshu222222 9 жыл бұрын
thanks a lot sir,.......the explanation is perfect .... thank u .......
@sadmanahmmed2214
@sadmanahmmed2214 8 жыл бұрын
your all vdos r awesome
@saifurrahmanbhuiyan925
@saifurrahmanbhuiyan925 9 жыл бұрын
The dynamic programming which works with bitwise operation , is called bitmask dp
@SonuSonu-tk5pk
@SonuSonu-tk5pk 7 жыл бұрын
zabardast samjhate hai aap sir ji
@ErfanHossainShoaib
@ErfanHossainShoaib 9 жыл бұрын
Please add a video for sub squire matrix max sum. Thanks for your best effort .......
@shyampatil8399
@shyampatil8399 7 жыл бұрын
This is a great help Tushar. Thanks a lot!
@TheDon640
@TheDon640 8 жыл бұрын
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..
@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
@Hameddelavar99
@Hameddelavar99 Жыл бұрын
I appreciate about this understandable video
@sandeepmukherjee8927
@sandeepmukherjee8927 2 жыл бұрын
Nice initiative sir but pls upload the code in C++ also.
@sonicabathija4464
@sonicabathija4464 9 жыл бұрын
simply justt waaooo explanation......
@banaaboy6504
@banaaboy6504 4 жыл бұрын
Five Stars!!! Thanks from Russia! ))))
@Sonakshi111
@Sonakshi111 8 жыл бұрын
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 8 жыл бұрын
I think that you could just write another condition: "Increment R, if L + R
@true_human_007
@true_human_007 6 жыл бұрын
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.
@aseemchakrabarthy9455
@aseemchakrabarthy9455 9 жыл бұрын
Really helpful !! Nice explanation ...Thankyou
@shekhataul5736
@shekhataul5736 4 жыл бұрын
Awesome tutorial, very thanks.
@vicky501513
@vicky501513 9 жыл бұрын
Thanku Sir.. Amazing explanation..
@yernartalgatuly4252
@yernartalgatuly4252 9 жыл бұрын
Thanks for explanation. I have a question. at 2:36. Why your currentSum is 5? It should be 4
@yernartalgatuly4252
@yernartalgatuly4252 9 жыл бұрын
+Tushar Roy Ok. It doesn't matter. But I undertood this algorithm by your video. Thanks
@sidhantkushwaha2766
@sidhantkushwaha2766 6 жыл бұрын
Excellent explanation.
@shilinwang2958
@shilinwang2958 3 жыл бұрын
NICE explanation
@abhishekjaiswal6492
@abhishekjaiswal6492 3 жыл бұрын
straightforward solution
@deepTh00ught
@deepTh00ught 3 жыл бұрын
For the one who are confused cuz of 2+2=5 it is wrong, but doesn't change the answer and algorithm
@jonathanhoyos8191
@jonathanhoyos8191 9 жыл бұрын
Thanx a lot!!! I really appreciate you to do this
@algorithmimplementer415
@algorithmimplementer415 4 жыл бұрын
You are a genius!!
@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 ).
@zhenqiangsu2966
@zhenqiangsu2966 3 жыл бұрын
The time complexity is col*col*row*row if include the Kadane algo? Like the brute force method?
@vin0summers
@vin0summers 9 жыл бұрын
Amazing description!
@meshmuhammad6927
@meshmuhammad6927 9 жыл бұрын
awesome man but it will be better to say lines of code or just a pseudo code while explaining , try this
@srikanthvelpuri2973
@srikanthvelpuri2973 3 жыл бұрын
Good Explanation
@bruce160280
@bruce160280 8 жыл бұрын
Nice explanation man
@bogdanrizescu8271
@bogdanrizescu8271 5 жыл бұрын
Well done, Tushar! :D
@jagdishwarbiradar1763
@jagdishwarbiradar1763 4 жыл бұрын
if go with rows like you are going with cols , can I get solution ?
@minakshikudalkar557
@minakshikudalkar557 4 жыл бұрын
We want a collab!! Tushar Roy and Ben (Back to Back SWE)!! haha Great explanation Tushar thank you :)
@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?
@USIndian51
@USIndian51 9 жыл бұрын
Wen, L = 0 and R = 0. isn't the max sum 4? Why is it 5?
@USIndian51
@USIndian51 9 жыл бұрын
***** Sorry, I didn't see the bubble.Anyway, thanks for the clarification.
@USIndian51
@USIndian51 9 жыл бұрын
***** By the way,is it possible for you to provide an explanation/solution for maximal palandrome using Suffix Trees? Thanks in advance.
@raviraaja1282
@raviraaja1282 7 жыл бұрын
I have checked your code in github, what if all elements in matrix are negative (< 0) , kadanes algorithm will result in 0 but , there is another approach to resolve (using dynamic programming) in dp approach how to find array index start and end ?
@freewind7894
@freewind7894 8 жыл бұрын
i watched a lot of your videos, good explanations. keep on bro``
@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.
@HimanshukhantwalDeveloper
@HimanshukhantwalDeveloper 8 жыл бұрын
easy explanation.. thanks for the help..
@apoorvchaturvedi6614
@apoorvchaturvedi6614 9 жыл бұрын
Another nice explanation....:)
@rajcodingworld7768
@rajcodingworld7768 9 жыл бұрын
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
@SergeyAngelov
@SergeyAngelov 5 жыл бұрын
Great explanation!
@shreyanshsharma8761
@shreyanshsharma8761 2 жыл бұрын
can it be done in better time complexity?
@ولاءعلي-خ8ط
@ولاءعلي-خ8ط 8 жыл бұрын
شرح جميل. شكرا استفدت كتير
@kuralamuthankathirvelan
@kuralamuthankathirvelan 5 жыл бұрын
Tushar roy fans hit like !❤
Burst Balloon Dynamic Programming[Leetcode]
27:22
Tushar Roy - Coding Made Simple
Рет қаралды 104 М.
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 147 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,7 МЛН
Random Emoji Beatbox Challenge #beatbox #tiktok
00:47
BeatboxJCOP
Рет қаралды 67 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 83 МЛН
2D Prefix Sum and Submatrix Sum Queries
5:12
Profound Academy
Рет қаралды 6 М.
Text Justification Dynamic Programming
15:31
Tushar Roy - Coding Made Simple
Рет қаралды 143 М.
Maximum Size Rectangle of All 1's Dynamic Programming
6:55
Tushar Roy - Coding Made Simple
Рет қаралды 181 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Binary Search : Median of two sorted arrays of different sizes.
24:48
Tushar Roy - Coding Made Simple
Рет қаралды 548 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 147 МЛН