Table of Contents: Geekin' 0:00 - 0:16 Going Meta 0:16 - 1:08 The Problem Introduction 1:08 - 2:47 Beginning of Brute Force Walkthrough 2:47 - 5:17 We Try The Next Top Left Planting 5:17 - 5:57 Analyzing The Brute Force's Runtime 5:57 - 6:33 Bounding The Work In Choosing Bottom Right Corners 6:33 - 7:31 Deriving A Lower Bound For The Brute Force 7:31 - 8:51 The Lower Bound For The Brute Force 8:51 - 9:38 Can We Do Better? 9:38 - 9:43 Beginning The Optimal Solution Walkthrough 9:43 - 10:18 Explaining The Algorithm 10:18 - 12:26 How Do We Pick An Optimal Top & Bottom For The Max Rectangle? 12:26 - 14:28 Walkthrough Continues 14:28 - 20:22 We Find The Best Rectangle 20:22 - 21:19 Walkthrough Continues 21:19 - 22:55 Recapping What Just Happened 22:55 - 23:50 Deriving The Optimal Solution Time Complexity 23:50 - 25:38 Space Complexity 25:38 - 26:07 Wrap Up 26:07 - 26:46 Mistakes: 11:17 -> The entry at index 3 in the runningRowSums array should be -8, not 8. Sorry. Yeah, the LED light is reflecting sharply off my glasses, I'll get something to diffuse the light better next time. The code for this problem is in the description. Fully commented for teaching purposes.
@Happy-on2is4 жыл бұрын
Hello bro I don't find any description? It was a good effort thankyou.
@BackToBackSWE4 жыл бұрын
The repository is deprecated, we only maintain backtobackswe.com now.
@niteshkhetan97573 жыл бұрын
@@BackToBackSWE This code is not even there in backtobackswe premium member access. Could you plz provide?
@bakiyalak19932 жыл бұрын
@Back To Back SWE i couldnt find code there as well
@Official-tk3nc4 жыл бұрын
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
@BackToBackSWE4 жыл бұрын
an inspiration
@mradulagrawal15794 жыл бұрын
Bro yahi tune tushar roy ke video me bhi likha hai naa 😜
@vend574 жыл бұрын
@@mradulagrawal1579 😂😂😂😂
@vanshsehgal94753 жыл бұрын
why there is even a need to tell from which college u are...
@mayukhchanda58054 жыл бұрын
This is such a smart and beautiful application of Kadane's algorithm. And explained so patiently and I'm such detailed manner, it was pure bliss to watch. Thank you for making such videos.
@BackToBackSWE4 жыл бұрын
thanks.
@wirito5 жыл бұрын
Normally, I skip videos that explain a concept in more than 10 minutes as usually they talk a lot but say very little. I’m glad I stayed for the long haul on this one Lol Excellent explanation. You speak clearly, make pauses, and do not leave anything to chance. Thank you! Ps- I don’t recommend starting your videos with those 2 guys goofing around. For the people who come across your channel for the very first time (such as me right now), this is a very good way to send off potential viewers. I almost gave up until you appeared.
@BackToBackSWE5 жыл бұрын
I do not remember a single word I said in this video whatsoever, glad it helped. And yeah, I am fully aware of this phenomenon, these older videos were around when no one watched.
@abhinavsingh42215 жыл бұрын
Buddy the way you explain makes brute-force also look awesome 😂😂 You are the best teacher!
@BackToBackSWE5 жыл бұрын
sure fam
@IamSinghJaskaran5 жыл бұрын
you good with code you are no fraud explain very well Knowledgeable as hell
@BackToBackSWE5 жыл бұрын
thanks
@conorhynes86334 жыл бұрын
@@BackToBackSWE that's a poem haha
@0anant04 жыл бұрын
Is writing Haikus your 'thing', Mr Jaskaran Singh? :-)
@suraj80875 жыл бұрын
The Thought process is what i needed. Thank You .
@BackToBackSWE5 жыл бұрын
sure
@VishalKumar-kr9me Жыл бұрын
You made my day, I saw so many posts and videos none of them explained why we are doing. I have been following you since 2019
@pratibhashrivastav57704 жыл бұрын
Your channel has one of the best explanations for every question. The way you describe the thought process behind and cover everything from brute force to explaining about complexities makes it way easier to understand. Thanks a lot!
@BackToBackSWE4 жыл бұрын
thanks and sure!
@Maholain6 жыл бұрын
Thank you so much for putting out these videos! You explain the thought process of coming up with the answer (arguably the most important part of the process; converting to code is usually quite easy once you understand the problem) way, way better than any other channel I've come across. Tiny mistake I noticed: at 13:00, the last entry of running sum should be -8, not 8. This threw me off a little when you said 6 was the largest contiguous subarray.
@BackToBackSWE6 жыл бұрын
Thank you, and got it, I updated the teacher's notes.
@AyushKarn254 жыл бұрын
You did a really good job by explaining what Tushar didn't. Finally understood this problem pretty well !
@BackToBackSWE4 жыл бұрын
ye
@anandartwork5 жыл бұрын
Great job! A nit to help others: In the running row sum for the first col when L = R= 0 at 14:00, the last row in the blue array has 8 while the original matrix has -8. Confuses why 6 is the largest when compared to 8, if you're caught off-guard! :-)
@BackToBackSWE5 жыл бұрын
thanks
@kartaLaLa4 жыл бұрын
your subscription should grow 10 times more, your teaching is clear and easy-to-understand, concise as gold.
@BackToBackSWE4 жыл бұрын
thanks haha
@anuragpateriya7874 жыл бұрын
LOved it bro.... this content deserves to be paid. clear,concise set of words and what not.
@BackToBackSWE4 жыл бұрын
thanks - and it is we have backtobackswe.com
@jishulayek82525 жыл бұрын
Thanks for uploading this. One of the best explanation I have came across. Keep up the good work.
@BackToBackSWE5 жыл бұрын
hey
@jishulayek82525 жыл бұрын
@@BackToBackSWE hello
@BackToBackSWE5 жыл бұрын
@@jishulayek8252 hi, this is Ben. hey
@bldbld184 жыл бұрын
I love the passion you are trying to explain and it's all crystal clear. Love your channel, good job mate!
@BackToBackSWE4 жыл бұрын
nice, thx
@arsalankhalid81704 жыл бұрын
What a clear and awesome explanation. The meat of the video starts at 10 min mark. That's where the row sum array is introduced. Left, Right, Top, Bottom and running row sum is what's needed Anytime we are trying to solve a 2D sum problem we need to check continuous sum of a 1D array ( the row sum in this example). In brief anytime we have an 'N' dimensional structure we will need to look at (N-1) running sum structure.
@grabsmench3 жыл бұрын
We need more people like you. Big thank from Vietnam!
@dominikcl14 жыл бұрын
I've been sitting trying to solve this as my algorithm assignment and all I could get after 5 hours of staring was the brute force solution. This opened my "third" eye. :D Great videos, thank you very much
@BackToBackSWE4 жыл бұрын
great
@adamyamishra91794 жыл бұрын
I've been here watchin you almost an year now, I've literally recommended your channel to everyone at my college NIT Jalandhar, one of the colleges of National Importance in India. We love you bro, your're the best thing that could have ever happened to KZbin!
@BackToBackSWE4 жыл бұрын
thanks and nice, and haha thanks
@jaideepmanhas60343 жыл бұрын
Lol why the flex though? NIT Jalandhar is a shit tier 2 college no company even cares about to visit.
@mizanali95293 жыл бұрын
"NIT Jalandhar, one of the colleges of National Importance in India" , one question, Why?😂
@VaibhavJain4 жыл бұрын
One of best explanation available online.
@BackToBackSWE4 жыл бұрын
thx
@favs52865 жыл бұрын
initially i thought this would be the same as Tushar Roy's tutorial vid, turns out it wasn't! the good part is you really added more to what was already explained by Tushar, great job!
@BackToBackSWE5 жыл бұрын
thanks
@srinaath98455 жыл бұрын
Wow thanks man. You explain so good that it's not even necessary to see the code for implementing 👌👏
@BackToBackSWE5 жыл бұрын
aw thx
@maripaz56505 жыл бұрын
So true. I'm binging these videos rn to study for my algorithms exam next week. I'm feeling better since I'm actually starting to understand dynamic programming. Thank you!
@BackToBackSWE5 жыл бұрын
@@maripaz5650 nice
@lucysmith90393 жыл бұрын
This explanation was very helpful and clear. You have a natural talent for teaching.
@kshitijagrawal26484 жыл бұрын
Bro just keep up the good work. The approach of solving the problems is really great.
@BackToBackSWE4 жыл бұрын
thanks
@tom0313choi5 жыл бұрын
Best explanation I have ever found
@BackToBackSWE5 жыл бұрын
thanks, hey
@arijitabanerjee95795 жыл бұрын
Really good videos. I am prepping for coding interviews and I guess this is one of the best resources that one can go through.
@BackToBackSWE5 жыл бұрын
ye
@consistentprani50343 жыл бұрын
where u got the placement
@dominikcl14 жыл бұрын
I have a question. If we knew that N or M is bigger. Would it help to transpose the matrix so that there are less running row sums to compute? If so, would the speedup be significant? My guess would be that it would make sense for matrices that have M >> N. Also it appears, that we would only save on space complexity, not time complexity in particular.
@JasonKT134 жыл бұрын
thank you, implementing the algorithm felt so soft after your explanation, keep up
@BackToBackSWE4 жыл бұрын
ye
@lizziedaffofil60643 жыл бұрын
Best DSA channel on the planet!
@wishfulthinker61394 жыл бұрын
i literally never look at the code as the explanation itself is soo good.
@BackToBackSWE4 жыл бұрын
nice!
@debayondharchowdhury26805 жыл бұрын
I just hit the gold-mine of Coding..... This is priceless... I'm very very thankful to the B2B_SWE guys...
@BackToBackSWE5 жыл бұрын
lol hi
@debayondharchowdhury26805 жыл бұрын
@@BackToBackSWE hi... I'm a final year undergrad student preparing for interview. And B2B_SWE is the best place because of its in-depth analysis of the problems and solutions is much needed to develop problem solving ability... Thanks man. By the way, where are you from, USA?
@BackToBackSWE5 жыл бұрын
@@debayondharchowdhury2680 sure and yes the united states
@adithyabhat47705 жыл бұрын
Very underrated channel...Amazing videos
@BackToBackSWE5 жыл бұрын
thanks
@Chesstreamer4 жыл бұрын
explanation is brilliant ,wow it seems so easy when u explained,great job,please keep doing this
@BackToBackSWE4 жыл бұрын
thanks and great
@premkumarsubbiah29723 жыл бұрын
Very genuine and i love the way you explain.. it leverages the thought process which really matters rather memorising!!!!
@hullyoung5 жыл бұрын
Thanks for the clear explanation, love that you paced the video really well
@BackToBackSWE5 жыл бұрын
thx
@lemonginger0015 жыл бұрын
man start taking system design topics as well .. u explain really well
@BackToBackSWE5 жыл бұрын
thanks
@r2123b4 жыл бұрын
your explanation is soooooo CLEAR and THOROUGH and you INDEED help me. Thank you for your sharing. :)
@BackToBackSWE4 жыл бұрын
thanks and great
@loudarck24022 жыл бұрын
Dude i wanna thanks you clear explanation and you really put work in ! and subscribed hope you keep posting algorthime problems
@harifrahman80544 жыл бұрын
Best video I have ever seen from u and also it's good that u are telling the time complexity at the end of video
@BackToBackSWE4 жыл бұрын
ye
@heyitsnikhil79565 жыл бұрын
Best explaination so far. Im going to watch the whole playlist in sequence. Im really enjoying it. 😮🙌 Why not sort the playlist on the basis of difficulty for people watching in sequence.. ✌️
@BackToBackSWE5 жыл бұрын
ha, never considered it, may do so
@yaosongding14795 жыл бұрын
This video is so great, really made the hard problem easy to understand.
@BackToBackSWE5 жыл бұрын
nice
@j.c98583 жыл бұрын
i would say this is the best explanation I found so far, thank you for sharing!
@Od2534 жыл бұрын
Great explanation on this one! Coming up with a solution and coding it up in 45 minutes seems unreasonable. Hoping people aren't actually being asked this in interviews!
@BackToBackSWE4 жыл бұрын
yes
@ASD-tg4zu3 жыл бұрын
I got it. It fucked me up.
@utkarsh_goel4 жыл бұрын
Was looking for the thought process for a similar problem. Found gold.
@BackToBackSWE4 жыл бұрын
great
@tanujabharti80434 жыл бұрын
Wow! A hard problem turned into an easy problem now Great explanation!!!!!
@BackToBackSWE4 жыл бұрын
sure!
@maharajak65783 жыл бұрын
one of the best explanation i came so far
@dikshantyadav11105 жыл бұрын
dude, you are just fab with explanation's and time complexity
@BackToBackSWE5 жыл бұрын
I try to be as fab as possible.
@AmberK2965 жыл бұрын
Clear explanations! Thank you so much!
@BackToBackSWE5 жыл бұрын
sure
@lotsalearn4 жыл бұрын
okay but what if the max contiguous subarray sum is present more than once, and is also greater than the max rectangle sum so far? what do we do then? (situation that occurs in 15:28)
@BackToBackSWE4 жыл бұрын
I don't remember the contents of this video and am fast replying to comments :/
@vanshajsingh63144 жыл бұрын
Damn! I Love you man! Such crystal clear explanations!
@BackToBackSWE4 жыл бұрын
thx
@vaibhavchauhan71794 жыл бұрын
omg such a fantastic explanation.....hats off man.
@BackToBackSWE4 жыл бұрын
thanks
@nutanchavan54643 жыл бұрын
Bruhhhhhh... you're awesome!! Totally loved the you taught. Thanks much for this video!!
@shubhamjindal92145 жыл бұрын
could not have got any better ...! nailed it ..!!
@BackToBackSWE5 жыл бұрын
THanks
@isaaczhanbaev36554 жыл бұрын
Dude, you are the best
@BackToBackSWE4 жыл бұрын
thanks.
@shishirkakhandki92303 жыл бұрын
Wonderful! Thanks for putting in all the effort!
@shobhitkumar68204 жыл бұрын
best tutorial of the question
@BackToBackSWE4 жыл бұрын
thx
@schu6494 жыл бұрын
awesome interpretation. Excellent job!
@BackToBackSWE4 жыл бұрын
thx
@wanwan62344 жыл бұрын
it says the code in the description, where is the description ? Thank you for your amazing explanation . This is the best I've heard .
@BackToBackSWE4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now. and thanks
@wanwan62344 жыл бұрын
@@BackToBackSWE Thank you
@aalekhsrivastava99733 жыл бұрын
For Time Complexity - Since we are finding all pairs of cols, that makes it O(cols^2). And with in each pair, we will do sequential passes over rows right? One pass to add new elements to update running row sum and the other pass to find max using Kadane's algorithm. That makes the passes as O(2*rows). Since 2 is constant, the final TC becomes O(cols^2 * rows). Is this right? Writing this just for clarification.
@Mohit-cn2us4 жыл бұрын
but you are not decrementing top left point, so how come you are checking each of the possible rectangle sum in DP approach ?
@naveenmeena18325 жыл бұрын
Hats Off dude. Gr8 way of explanation Tushar Roy can learn a thing or two from you
@BackToBackSWE5 жыл бұрын
hahahahaha ok
@AnhLe-hc8qm4 жыл бұрын
Thanks for your clear explaination !!!
@BackToBackSWE4 жыл бұрын
sure
@qingli84662 жыл бұрын
Thanks for your explanation!
@roinskitty6 ай бұрын
thanks man that was a great explanation
@yutaitadori73183 жыл бұрын
It turned out awesome ♥️
@孫傅康10 ай бұрын
NIce explanation! Thank you so much!
@blackkiritok4 жыл бұрын
I have a quick modification questions. If we wanted to find squares instead of rectangles, how would you approach this problem? I am not able to figure that out
@BackToBackSWE4 жыл бұрын
im not sure dont remember tbh
@Jay-dm4id4 жыл бұрын
Similar to rectangle but only restriction is instead of kadane,you need to find max subarray of size K( K = R-L+1) in the sum column. This can also be done in o(m) time,so complexity is same.
@oscaropdyou4 жыл бұрын
"We will try all combinations of left and right ending points for the possible 2D rectangle." - Can we use range sum querying per row to reduce the time complexity to O(rows*cols)?
@BackToBackSWE4 жыл бұрын
I'm not sure don't remember the problem much
@oscaropdyou4 жыл бұрын
@@BackToBackSWE I was referring to this - kzbin.info/www/bejne/kH6yd6B-d7t4mck
@varunagarwal51894 жыл бұрын
another amazing explanation
@BackToBackSWE4 жыл бұрын
thx
@ManishSharma-fi2vr3 жыл бұрын
Thanks for this kind of explanation!
@lifeofMani975 жыл бұрын
You are the best bro !
@BackToBackSWE5 жыл бұрын
thx
@sumana_193 жыл бұрын
Thank you so much man. You made it crystal clear. Really appreciate your efforts.
@VIJAYKUMAR-tn1kr3 жыл бұрын
So much helpful.Thank you .
@adityasrivastava79563 жыл бұрын
HEY JOHN LEGEND>>NICE WORK BUDDY>>YOU ARE A GREAT SINGER INDEED
@LegitGamer23453 жыл бұрын
awesome explanation !!!!
@shivamjalotra79194 жыл бұрын
Wow, ThankYou. You rock.
@BackToBackSWE4 жыл бұрын
thanks
@puperhacker21505 жыл бұрын
Excellent video. Thanks!
@BackToBackSWE5 жыл бұрын
sure
@ketiperanidze86034 жыл бұрын
So the best time complexity we can get is o(n^3) (if rows and columns are both equal to n). I wonder if there is a better solution.
@abhigupta66815 жыл бұрын
your content is great. Thank you
@BackToBackSWE5 жыл бұрын
thx
@ManishSharma-fi2vr3 жыл бұрын
DRY run is awesome!
@zivashnivash25123 жыл бұрын
Thanks for the explanation, where is the code for this algorithm? I can't find it
@marcousosewelle55014 жыл бұрын
Great work dude! Nice one :-)
@BackToBackSWE4 жыл бұрын
Thanks
@olicmoon5 жыл бұрын
Nicely explained
@BackToBackSWE5 жыл бұрын
thanks
@Ritikjain92115 жыл бұрын
your video is good, gfg article does not explain the solution to this question properly.
@BackToBackSWE5 жыл бұрын
thx
@Calisthenoob6 жыл бұрын
Hey, great explanation as always, and while I didn’t care much for the lighting, the 2 separate boards feels kinda odd to me.. Also, are you gonna do a graph boot camp similar to the one you did for the tree anytime soon? Would be a huge help!
@BackToBackSWE6 жыл бұрын
I can do a graph video...it'll happen eventually. Really the core thing you need to understand about graphs is DFS and BFS which I covered a while back (kzbin.info/www/bejne/inrFhpiboNiLmas). Every acyclic connected graph is a tree, and all trees are acyclic connected graphs. Also, when you say "I didn’t care much for the lighting" does that indicate indifference to it or is it worse than other videos? And yeah understood, I will keep to 1 large board.
@Calisthenoob6 жыл бұрын
@@BackToBackSWE I meant the lighting didn't make a difference to me.. Thanks for the link, i'll check it out!
@BackToBackSWE6 жыл бұрын
@@Calisthenoob ok great
@nhuquantcheng71122 жыл бұрын
Thank you so much for your clear and intelligent explanation, it helped me a lot with my homework :D the best channel ever
@BackToBackSWE2 жыл бұрын
Thank You!! Do check out backtobackswe.com/platform/content and please recommend us to your family and friends :)
@ujjawaltyagi3025 жыл бұрын
I don't think your code will work when all entries are negative as your kadanae function returns values greater than or equal to zero. if you substitute by this it should do fine. public int maxSubArray(int[] nums) { int maxEndingHere=0; int max=Integer.MIN_VALUE; int cS=0,cE=0; int gS=-1,gE=-1; for(int i=0;imaxEndingHere+nums[i]){ cS=i;cE=i; maxEndingHere=nums[i]; }else{ cE=i; maxEndingHere=maxEndingHere+nums[i]; } if(maxEndingHere>max){ gS=cS;gE=cE; max=maxEndingHere; } } System.out.print(gS+" "+gE); return max; } great explanation btw.
@BackToBackSWE5 жыл бұрын
yeah it won't work with negatives
@BelalMoawadOfficial4 жыл бұрын
Thank u, u are incredible
@BackToBackSWE4 жыл бұрын
sure
@SmokyBigSmoke4 жыл бұрын
You are amazing.TYSM
@BackToBackSWE4 жыл бұрын
sure!
@ankitgoyal85564 жыл бұрын
Like and comment-done Prerequisites done for watching video ;)
@BackToBackSWE4 жыл бұрын
great ha
@sebastianvillamil93193 жыл бұрын
Sorry where is the code? Great video, it helped me so much!
@pranjlisingh64904 жыл бұрын
can u please make a video on how to find kth largest element in a row wise and column wise sorted matrix using binary search
@BackToBackSWE4 жыл бұрын
ye
@pranjlisingh64904 жыл бұрын
@@BackToBackSWE will wait for the video...thanks
@nemesis94105 жыл бұрын
ummmm... that's great and all, but I don't see Dynamic Programming here. What's the semantic array? How do you reuse the solutions for smaller sub-problems?
@BackToBackSWE5 жыл бұрын
I don't remember the solution/this video too much, refresh me
@nemesis94105 жыл бұрын
@@BackToBackSWE Hey! I was just looking to solve this problem using DP, but in your case you use Kadane's algorithm, which according to the internets is not considered DP by everyone (idk how that works tbh). What's I'm used to is defining a semantic array (similar to knapsack problems) and reusing array entries to reduce the problem to a subproblem. So I'm just asking if I missed any of that here?
@Ayushkumar-xj9vl4 жыл бұрын
I wish we can meet someday. Thank you for your efforts !!
@BackToBackSWE4 жыл бұрын
sure
@AnshMehtaGR84 жыл бұрын
Damn you reply to every single comment, also the new setup is quite good.
@BackToBackSWE4 жыл бұрын
yes, I do. and thx
@Epictetus777 Жыл бұрын
Can we use recursion in this. ??
@bhavukgarg36195 жыл бұрын
Nice explanation
@BackToBackSWE5 жыл бұрын
hey
@ritikagupta88473 жыл бұрын
The brute force time complexity is O(row^3* col^3).