I really gained confidence in DP by watching your video , thanks Errichto !!
@johnvanschultz22978 ай бұрын
My man didn't even bother running the tests he went right to submit. I will never be that brave
@gompro4 жыл бұрын
Such a perfect visualization of the problem. Absolutely my go-to channel for algorithms.
@dz_s4 жыл бұрын
One of the best competitive programming channels to my mind. I would really like to see special playlist with "Hard" level problems (leetcode examples possible). To me it's still quite hard to see patterns in such kind of problems. Thanks!
@fycode4 жыл бұрын
Yeah, that would be really helpful. I am trying to crack Hard problems so such resources would be a gold mine for sure :)
@BedoEbied4 жыл бұрын
Best free explanation in the market, love you dude! ❤️
@adibhasan81144 жыл бұрын
ABSOLUTE MASTERCLASS EXPLANATION !!! THANKS A LOT ERRICHTO LOOKING FORWARD TO THE 2D PREFFIX SUM SOLUTION !!!!
@ayushpathak49182 жыл бұрын
best explanation for this question till now.... Understood it after two days.. Thanks man
@whitesalmon09254 жыл бұрын
the first 2:45 mins were ASMR right there!! I had no idea what is going on, but I enjoyed watching them :). Also the explanation at 8:40 was awesome
@limakbear70293 жыл бұрын
Exactly, I got the idea, DP is awesome
@shivanshkasaudhan41306 ай бұрын
Thanks Errichto, the solution was really an out of the box solution.
@HalocaneJump Жыл бұрын
Love your explanations! So simple but clearly communicated and effective!
@Kranach7774 жыл бұрын
I knew I had to use DP for this problem, but I couldnt figure out the idea how to count dp[i][j]. I struggled for some time but after an hour I gave up and looked up solution. Need some more dp practice I guess ;P
@miteshkumar31834 жыл бұрын
I was trying to store the maximum height and maximum width separately, and then I realized that it is a square so they both have to be the same.
@ZzwhiskeybkszZ4 жыл бұрын
me too! I knew it was DP but couldn't derive the relation. Keep practicing!
@kalapnaa86232 жыл бұрын
An N*N matrix containing 1s and Os is given as the input to the program. The program must print the number of 2x2 unit matrices in the given matrix. A matrix is said to be unit matrix if all the integers are 1. Also, consider the overlapping matrices.
@kalapnaa86232 жыл бұрын
Ans plz
@sankarraja57092 жыл бұрын
Ans plz
@rajaryansingh31564 жыл бұрын
I m struggling with dp and recursion, but your videos help a lot. 💓
@vincentchang87482 жыл бұрын
my brain is so smooth
@bethsuni40114 жыл бұрын
Going through the test case step by step was nice.
@hilmybyte4 жыл бұрын
the best explanation for me as a beginner
@uneq95894 жыл бұрын
Errichto be like, "And this is the hardest part of the problem..." + " ..but not for me :P"
@vijay68774 жыл бұрын
tbh I really wanted to quit programming it looks like this is not for me. but whenever I watch your video this give me little hope. and I Think I should give it one more try. Thanks Errichto.
@gianlucavigano7114 жыл бұрын
Don't give up!! If you like programming you should never stop practicing it... with time, hard work and passion you'll see great improvements, as with everything
@milanboroja70944 жыл бұрын
Who can press dislike on this ?! You are awesome man!
@saicharan8824 жыл бұрын
Great video. Nice explanation. New thing learned is how to use min of 3 numbers.
@romokdas84944 жыл бұрын
When to use dynamic programming instead of greedy solutions in optimization problems? Do you use some tricks or its pure intuition?
@Errichto4 жыл бұрын
I explained my intuition and general approach in a series of 3 dp lectures, find them in my playlists kzbin.info/door/Br_Fu6q9iHYQCh13jmpbrgplaylists
@sauravpaul41314 жыл бұрын
Thank you for this great explanation.
@superdonkhalil4 жыл бұрын
wow your video really helps me to understand algorithm! thx!
@kemosabe65214 жыл бұрын
I would love to see Top-down Approach instead, as yesterday. Well i got some hint and will try to make my code works. 😁 FYI i am very beginner in Dp nd solved it similar way around 4hr after heavy debugging ☹️
@imdeadshot36324 жыл бұрын
hard to derive prefix sum for 2d arrays, a video on that would be of much help! also, i learnt min(3 elements) can be done calling once and wrapping all inside {}, till now i used to do min(a,b,c) = min(min(a,b), c) . Thanks a lot for this trivial yet code shortening trick!
@kacperozieblowski38093 жыл бұрын
I saw that when you didn't include the dp[row-1][col-1] and I was so proud of myself for seeing it lol. Interesting problem btw.
@satyakimajumder19764 жыл бұрын
Fantastic explanation ! I request you to cover subsequence and subarray problems, like getting subsequences of array whose length is a power of 2 and find the maximum element in each subsequence or subarray such that the sum of those is maximum (For example).
@БлаговестГеоргиев-й9р4 жыл бұрын
What if problem was to find max rectangle in matrix ,I cant do this
@Errichto4 жыл бұрын
It's a much much harder problem then. The solution in Polish is here, you can read code at the bottom www.deltami.edu.pl/temat/informatyka/algorytmy/2015/10/27/Zliczamy_puste_prostokaty/
@sourabhkhandelwal15684 жыл бұрын
First try the easier version. The easier version is to find the Maximum Rectangular Area in a Histogram. A Histogram is basically an Array of non negative numbers, the value at the ith index represents the height of the rectangular bar at the Index. So, the Histogram is essentially an array of unit width rectangles where the height is given in an array. The fastest approach to solve this problem is using a stack. The problem you are asking is basically an extension of the above problem.
@БлаговестГеоргиев-й9р4 жыл бұрын
@@sourabhkhandelwal1568 that is my solution for histogram,now i will think about max rect in matrix #include using namespace std; int h[1000]; int main () { int n; cin>>n; int maxh=0,minh=999999999; for(int i=0;i>h[i];maxh=max(maxh,h[i]);minh=min(minh,h[i]);} int ans=0; for(int p=minh;p
@lovleshbhatt77974 жыл бұрын
@@Errichto My approach is:-> We just make an 2D array of data type pair and use dp , but at every point for the first element of pair i,e, dp[i][j].first = dp[i-1][j]+1; // consider for find the max length vertically similarly dp[i][j].second=dp[i][j-1]+1; // consider for finding the max length horizontally Note-: if at any point mat[i][j]=0, we initialise dp[i][j].first=0; dp[i][j].second=0; Also use a 2 varible max_x, max_y to store the max value of dp[i][j].first and dp[i][j].second at every instance of traversing Thank You!! BTW BIG FAN, AND HUGE LOVE & RESPECT FROM INDIA
@joshmiller77484 жыл бұрын
Is www.geeksforgeeks.org/maximum-size-rectangle-binary-sub-matrix-1s/ what you are looking for?
@joshmiller77484 жыл бұрын
Hi Errichto. I am a big fan of your channel. I am completely new to programming, only know HTML and CSS. I want to learn JavaScript and want a book, what book would you suggest that teaches from ground up? Many books seem to assume that you have already little experience and know basics. Which book would you recommend that teaches from ground up?
@satyammishra-xb3hs2 жыл бұрын
Best Explanation of this problem on yt. Can anyone suggest more problems like this for practice??
@sounishnath5134 жыл бұрын
Genius like every alltime
@ayushkhandelwal67774 жыл бұрын
New to this channels just clicked on the video and at the end like and subscribed dude how much years did it took u to reach at this level
@shivaraj-bh4 жыл бұрын
I first solved the brute Force way O(n^4), then I improved the solution using 2d prefix sums in O(n^3) (both of which were accepted), then I solved it using DP O(n^2) time and O(n^2) space... Went through the solution and then solved it in O(n) space.
@barongrmel37974 жыл бұрын
I used prefix sum and binary search, but this idea is was really neat
@judgebot73532 жыл бұрын
You're just awesome mate!
@ankursuri38534 жыл бұрын
You are a genius dude! You rock!
@nitindas2083 жыл бұрын
Understanding your explanation is easy but how do come up with these types of solution in contest??
@TwoTeaTee4 жыл бұрын
Such a great explaination! 🔥
@sahilanand303 жыл бұрын
Best explanation
@smoothCriminaI3 жыл бұрын
Excellent explanation 😊
@yashrastogi37264 жыл бұрын
Such a easy question , but after seeing your explanation 😀
@leetcodesolver90924 жыл бұрын
Quite impressive solution and really nice explanation. I really missed such a brilliant solution and went with stack based solution to achieve same time space complexity. By the way, is there any simpler way to solve the same problem if it asks for largest Rectangle instead of largest Square?
@Errichto4 жыл бұрын
Copying from another comment: It's a much much harder problem then. The solution in Polish is here, you can read code at the bottom www.deltami.edu.pl/temat/informatyka/algorytmy/2015/10/27/Zliczamy_puste_prostokaty/
@akashdubey83414 жыл бұрын
What's the stack based solution
@arsenypogosov72062 жыл бұрын
@@Errichto It seems to be an O(n^2) solution. Actually you can solve it in O(n). I can describe the solution if anyone is interested.
@juanfeliperubio1374 жыл бұрын
What if we wanted to find the maximal rectangle of one's? Thanks for your videos!
@mandavasairaghavendradines65824 жыл бұрын
Awsome explanation!!
@axlrose50824 жыл бұрын
I'm just on the easy hackerrank's ones, idk what I'm doing here but nice videos xD
@__________________________69103 жыл бұрын
1 min 30sec are you kidding me. You are god
@FirefoxGuy183 жыл бұрын
thank you so much, great way to explain
@egor.okhterov3 жыл бұрын
Could you, please, compare this problem with finding the largest rectangle in the same matrix? Why doesn't the same DP approach cannot be used for finding the largest rectangle?
@toekneema3 жыл бұрын
Great visual
@mdfahad27264 жыл бұрын
Can you tell about the timer you use. I want to practice some problem with some time constraints.
@imsiddu4 жыл бұрын
please make a video on explaining your template for debugging...
@lovvyparhar3934 жыл бұрын
should I practice topics like DP on geeks for geeks list to learn the concepts or just do problems on platforms like cf and learn them gradually?
@patrickdaniel23634 жыл бұрын
It can be solved without extra space, just changing the original matrix if it's allowed.
@TrickyCat4 жыл бұрын
Hi. What do you use for drawings (like the one in this video)?
@hellowill4 жыл бұрын
What about maximal rectangle?
@workhardplayhard04 жыл бұрын
Hi, what if the question become area of largest rectangle, not square ? Is there a dp solution to that as well?
@workhardplayhard04 жыл бұрын
@Arif Rezai wow ok thanks mate
@코연몬4 жыл бұрын
very useful
@dpark-z44 жыл бұрын
Thank you🤩
@Chris_Lan4 жыл бұрын
What do you use to draw those explanation?
@mohdekrama85973 жыл бұрын
loved it💓
@kolloktn4 жыл бұрын
Thanks
@petrob1234 жыл бұрын
This is great
@shashanktiwari44424 жыл бұрын
When are u doing codejam training livestream?? Waiting for it :D
@Errichto4 жыл бұрын
Sometime in May for sure!
@PasselivreEdicoes4 жыл бұрын
I did 2d prefix sum with binary search, I think it's easier to come up with than DP, if you know 2d prefix sums
@piyushnaithani76894 жыл бұрын
What if ques says, find the maximal rectangle of 1s???
@lovleshbhatt77974 жыл бұрын
We just make an 2D array of data type pair and use dp , but at every point for the first element of pair i,e, dp[i][j].first = dp[i-1][j]+1; // consider for find the max length vertically similarly dp[i][j].second=dp[i][j-1]+1; // consider for finding the max length horizontally Note-: if at any point mat[i][j]=0, we initialise dp[i][j].first=0; dp[i][j].second=0; Also use a 2 varible max_x, max_y to store the max value of dp[i][j].first and dp[i][j].second at every instance of traversing
@abdulsalamkhan19864 жыл бұрын
What a coincidence, I too got same WA twice
@oudarjatanmoy3844 жыл бұрын
best regards from me.. i want to know if i taka max(dp[i-1][j-1],dp[i-1][j],dp[i][j-1]) +1 it will work on maximum rectangle of one????
@mahindrakatta29578 ай бұрын
what if the question asks the maximum rectangle possible?
@mridulkumar7864 жыл бұрын
Guy who tried hard to understand dynamic programming but cannot get it, disliked this video
@faridgadzhiev14404 жыл бұрын
Great explanation as always. Are you going to cover May challenge as well? leetcode.com/explore/challenge/card/may-leetcoding-challenge/
@c_tanki2074 жыл бұрын
No he told in his other live stream that he will be taking a break from leet code coz it bores him now... He will now go for topcoder an codeforces I presume
@KumarShanoo4 жыл бұрын
what is the app u use for timer
@lumigg25564 жыл бұрын
This is the closest we can get of an IRL Neo
@suvadeepghoshal4 жыл бұрын
Visit India once.. kamil and organize a camp. I want to meet you live !!! (Super excited)
@sourabhkhandelwal15684 жыл бұрын
Amrita University does regular training camps. When I participated in ICPC the teams there got invite for the training camp that was going to take place the next year. Codechef can make Kamil the guest invites of one such events. Back in college, I didn't have money to attend CP bootcamps but now cause of having a job I can afford them unless they are too costly. Will be looking forward to join if Errichto is really teaching something in them. :)
@rajshekhar29534 жыл бұрын
In a time of coronavirus pandemic, no one is allowed to do the live gathering. Who will be responsible, god forbid, for his misshapen?
@suvadeepghoshal4 жыл бұрын
@@rajshekhar2953 not now.. -_- after this all cools down..
@TanvirSojal4 жыл бұрын
@@suvadeepghoshal He visited India for IPC camp 2017. You can watch the videos here: kzbin.info/aero/PLi0ZM-RCX5nvImim3_ilsdLOtDDkOWt-X
@sourabhkhandelwal15684 жыл бұрын
@@TanvirSojal wow, thanks for this. Edit - Sound quality is too bad.
@thatnaman3 жыл бұрын
It takes me 2 mins to read and understand what the question is asking for.
@hemanthkotagiri88654 жыл бұрын
I just don't understand anything about what you did there. How do I go about this? Please, can you suggest to me improve my competitive programming skills?
@sangramjitchakraborty78454 жыл бұрын
Read up on dynamic programming
@jimmyshenmusic4 жыл бұрын
A similar problem in a recent leetcode contest. leetcode.com/problems/number-of-substrings-with-only-1s/
@Heulitig1174 жыл бұрын
When you realise that his typing speed is faster than the speed you are probably thinking the solution.
@rentib91364 жыл бұрын
I hate dp. Give me a problem on finger tree
@parthokunda4 жыл бұрын
I tried soving the problem but got 0 as answer whatever I tried. Finally, watching the video I found that values are characters, not integers :( . what a waste of time.
@satyampatidar58484 жыл бұрын
3×5 is not the square in red line
@Errichto4 жыл бұрын
Did I claim otherwise? Timestamp please.
@jameysiddiqui69104 жыл бұрын
your face should be at bottom right corner and editor should be up
@user-rz8lc3zl7k4 жыл бұрын
Hey brother do you read the Bible? Remember this life is only temporary
@sankarraja57092 жыл бұрын
An N*N matrix containing 1s and Os is given as the input to the program. The program must print the number of 2x2 unit matrices in the given matrix. A matrix is said to be unit matrix if all the integers are 1. Also, consider the overlapping matrices.