Maximal Square of Ones (LeetCode Day 27)

  Рет қаралды 40,775

Errichto Algorithms

Errichto Algorithms

Күн бұрын

Пікірлер: 119
@ShivamSingh-vu8vq
@ShivamSingh-vu8vq 4 жыл бұрын
I really gained confidence in DP by watching your video , thanks Errichto !!
@johnvanschultz2297
@johnvanschultz2297 8 ай бұрын
My man didn't even bother running the tests he went right to submit. I will never be that brave
@gompro
@gompro 4 жыл бұрын
Such a perfect visualization of the problem. Absolutely my go-to channel for algorithms.
@dz_s
@dz_s 4 жыл бұрын
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!
@fycode
@fycode 4 жыл бұрын
Yeah, that would be really helpful. I am trying to crack Hard problems so such resources would be a gold mine for sure :)
@BedoEbied
@BedoEbied 4 жыл бұрын
Best free explanation in the market, love you dude! ❤️
@adibhasan8114
@adibhasan8114 4 жыл бұрын
ABSOLUTE MASTERCLASS EXPLANATION !!! THANKS A LOT ERRICHTO LOOKING FORWARD TO THE 2D PREFFIX SUM SOLUTION !!!!
@ayushpathak4918
@ayushpathak4918 2 жыл бұрын
best explanation for this question till now.... Understood it after two days.. Thanks man
@whitesalmon0925
@whitesalmon0925 4 жыл бұрын
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
@limakbear7029
@limakbear7029 3 жыл бұрын
Exactly, I got the idea, DP is awesome
@shivanshkasaudhan4130
@shivanshkasaudhan4130 6 ай бұрын
Thanks Errichto, the solution was really an out of the box solution.
@HalocaneJump
@HalocaneJump Жыл бұрын
Love your explanations! So simple but clearly communicated and effective!
@Kranach777
@Kranach777 4 жыл бұрын
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
@miteshkumar3183
@miteshkumar3183 4 жыл бұрын
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.
@ZzwhiskeybkszZ
@ZzwhiskeybkszZ 4 жыл бұрын
me too! I knew it was DP but couldn't derive the relation. Keep practicing!
@kalapnaa8623
@kalapnaa8623 2 жыл бұрын
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.
@kalapnaa8623
@kalapnaa8623 2 жыл бұрын
Ans plz
@sankarraja5709
@sankarraja5709 2 жыл бұрын
Ans plz
@rajaryansingh3156
@rajaryansingh3156 4 жыл бұрын
I m struggling with dp and recursion, but your videos help a lot. 💓
@vincentchang8748
@vincentchang8748 2 жыл бұрын
my brain is so smooth
@bethsuni4011
@bethsuni4011 4 жыл бұрын
Going through the test case step by step was nice.
@hilmybyte
@hilmybyte 4 жыл бұрын
the best explanation for me as a beginner
@uneq9589
@uneq9589 4 жыл бұрын
Errichto be like, "And this is the hardest part of the problem..." + " ..but not for me :P"
@vijay6877
@vijay6877 4 жыл бұрын
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.
@gianlucavigano711
@gianlucavigano711 4 жыл бұрын
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
@milanboroja7094
@milanboroja7094 4 жыл бұрын
Who can press dislike on this ?! You are awesome man!
@saicharan882
@saicharan882 4 жыл бұрын
Great video. Nice explanation. New thing learned is how to use min of 3 numbers.
@romokdas8494
@romokdas8494 4 жыл бұрын
When to use dynamic programming instead of greedy solutions in optimization problems? Do you use some tricks or its pure intuition?
@Errichto
@Errichto 4 жыл бұрын
I explained my intuition and general approach in a series of 3 dp lectures, find them in my playlists kzbin.info/door/Br_Fu6q9iHYQCh13jmpbrgplaylists
@sauravpaul4131
@sauravpaul4131 4 жыл бұрын
Thank you for this great explanation.
@superdonkhalil
@superdonkhalil 4 жыл бұрын
wow your video really helps me to understand algorithm! thx!
@kemosabe6521
@kemosabe6521 4 жыл бұрын
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 ☹️
@imdeadshot3632
@imdeadshot3632 4 жыл бұрын
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!
@kacperozieblowski3809
@kacperozieblowski3809 3 жыл бұрын
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.
@satyakimajumder1976
@satyakimajumder1976 4 жыл бұрын
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р
@БлаговестГеоргиев-й9р 4 жыл бұрын
What if problem was to find max rectangle in matrix ,I cant do this
@Errichto
@Errichto 4 жыл бұрын
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/
@sourabhkhandelwal1568
@sourabhkhandelwal1568 4 жыл бұрын
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р
@БлаговестГеоргиев-й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
@lovleshbhatt7797
@lovleshbhatt7797 4 жыл бұрын
​@@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
@joshmiller7748
@joshmiller7748 4 жыл бұрын
Is www.geeksforgeeks.org/maximum-size-rectangle-binary-sub-matrix-1s/ what you are looking for?
@joshmiller7748
@joshmiller7748 4 жыл бұрын
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-xb3hs
@satyammishra-xb3hs 2 жыл бұрын
Best Explanation of this problem on yt. Can anyone suggest more problems like this for practice??
@sounishnath513
@sounishnath513 4 жыл бұрын
Genius like every alltime
@ayushkhandelwal6777
@ayushkhandelwal6777 4 жыл бұрын
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-bh
@shivaraj-bh 4 жыл бұрын
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.
@barongrmel3797
@barongrmel3797 4 жыл бұрын
I used prefix sum and binary search, but this idea is was really neat
@judgebot7353
@judgebot7353 2 жыл бұрын
You're just awesome mate!
@ankursuri3853
@ankursuri3853 4 жыл бұрын
You are a genius dude! You rock!
@nitindas208
@nitindas208 3 жыл бұрын
Understanding your explanation is easy but how do come up with these types of solution in contest??
@TwoTeaTee
@TwoTeaTee 4 жыл бұрын
Such a great explaination! 🔥
@sahilanand30
@sahilanand30 3 жыл бұрын
Best explanation
@smoothCriminaI
@smoothCriminaI 3 жыл бұрын
Excellent explanation 😊
@yashrastogi3726
@yashrastogi3726 4 жыл бұрын
Such a easy question , but after seeing your explanation 😀
@leetcodesolver9092
@leetcodesolver9092 4 жыл бұрын
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?
@Errichto
@Errichto 4 жыл бұрын
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/
@akashdubey8341
@akashdubey8341 4 жыл бұрын
What's the stack based solution
@arsenypogosov7206
@arsenypogosov7206 2 жыл бұрын
​@@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.
@juanfeliperubio137
@juanfeliperubio137 4 жыл бұрын
What if we wanted to find the maximal rectangle of one's? Thanks for your videos!
@mandavasairaghavendradines6582
@mandavasairaghavendradines6582 4 жыл бұрын
Awsome explanation!!
@axlrose5082
@axlrose5082 4 жыл бұрын
I'm just on the easy hackerrank's ones, idk what I'm doing here but nice videos xD
@__________________________6910
@__________________________6910 3 жыл бұрын
1 min 30sec are you kidding me. You are god
@FirefoxGuy18
@FirefoxGuy18 3 жыл бұрын
thank you so much, great way to explain
@egor.okhterov
@egor.okhterov 3 жыл бұрын
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?
@toekneema
@toekneema 3 жыл бұрын
Great visual
@mdfahad2726
@mdfahad2726 4 жыл бұрын
Can you tell about the timer you use. I want to practice some problem with some time constraints.
@imsiddu
@imsiddu 4 жыл бұрын
please make a video on explaining your template for debugging...
@lovvyparhar393
@lovvyparhar393 4 жыл бұрын
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?
@patrickdaniel2363
@patrickdaniel2363 4 жыл бұрын
It can be solved without extra space, just changing the original matrix if it's allowed.
@TrickyCat
@TrickyCat 4 жыл бұрын
Hi. What do you use for drawings (like the one in this video)?
@hellowill
@hellowill 4 жыл бұрын
What about maximal rectangle?
@workhardplayhard0
@workhardplayhard0 4 жыл бұрын
Hi, what if the question become area of largest rectangle, not square ? Is there a dp solution to that as well?
@workhardplayhard0
@workhardplayhard0 4 жыл бұрын
@Arif Rezai wow ok thanks mate
@코연몬
@코연몬 4 жыл бұрын
very useful
@dpark-z4
@dpark-z4 4 жыл бұрын
Thank you🤩
@Chris_Lan
@Chris_Lan 4 жыл бұрын
What do you use to draw those explanation?
@mohdekrama8597
@mohdekrama8597 3 жыл бұрын
loved it💓
@kolloktn
@kolloktn 4 жыл бұрын
Thanks
@petrob123
@petrob123 4 жыл бұрын
This is great
@shashanktiwari4442
@shashanktiwari4442 4 жыл бұрын
When are u doing codejam training livestream?? Waiting for it :D
@Errichto
@Errichto 4 жыл бұрын
Sometime in May for sure!
@PasselivreEdicoes
@PasselivreEdicoes 4 жыл бұрын
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
@piyushnaithani7689
@piyushnaithani7689 4 жыл бұрын
What if ques says, find the maximal rectangle of 1s???
@lovleshbhatt7797
@lovleshbhatt7797 4 жыл бұрын
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
@abdulsalamkhan1986
@abdulsalamkhan1986 4 жыл бұрын
What a coincidence, I too got same WA twice
@oudarjatanmoy384
@oudarjatanmoy384 4 жыл бұрын
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????
@mahindrakatta2957
@mahindrakatta2957 8 ай бұрын
what if the question asks the maximum rectangle possible?
@mridulkumar786
@mridulkumar786 4 жыл бұрын
Guy who tried hard to understand dynamic programming but cannot get it, disliked this video
@faridgadzhiev1440
@faridgadzhiev1440 4 жыл бұрын
Great explanation as always. Are you going to cover May challenge as well? leetcode.com/explore/challenge/card/may-leetcoding-challenge/
@c_tanki207
@c_tanki207 4 жыл бұрын
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
@KumarShanoo
@KumarShanoo 4 жыл бұрын
what is the app u use for timer
@lumigg2556
@lumigg2556 4 жыл бұрын
This is the closest we can get of an IRL Neo
@suvadeepghoshal
@suvadeepghoshal 4 жыл бұрын
Visit India once.. kamil and organize a camp. I want to meet you live !!! (Super excited)
@sourabhkhandelwal1568
@sourabhkhandelwal1568 4 жыл бұрын
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. :)
@rajshekhar2953
@rajshekhar2953 4 жыл бұрын
In a time of coronavirus pandemic, no one is allowed to do the live gathering. Who will be responsible, god forbid, for his misshapen?
@suvadeepghoshal
@suvadeepghoshal 4 жыл бұрын
@@rajshekhar2953 not now.. -_- after this all cools down..
@TanvirSojal
@TanvirSojal 4 жыл бұрын
@@suvadeepghoshal He visited India for IPC camp 2017. You can watch the videos here: kzbin.info/aero/PLi0ZM-RCX5nvImim3_ilsdLOtDDkOWt-X
@sourabhkhandelwal1568
@sourabhkhandelwal1568 4 жыл бұрын
@@TanvirSojal wow, thanks for this. Edit - Sound quality is too bad.
@thatnaman
@thatnaman 3 жыл бұрын
It takes me 2 mins to read and understand what the question is asking for.
@hemanthkotagiri8865
@hemanthkotagiri8865 4 жыл бұрын
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?
@sangramjitchakraborty7845
@sangramjitchakraborty7845 4 жыл бұрын
Read up on dynamic programming
@jimmyshenmusic
@jimmyshenmusic 4 жыл бұрын
A similar problem in a recent leetcode contest. leetcode.com/problems/number-of-substrings-with-only-1s/
@Heulitig117
@Heulitig117 4 жыл бұрын
When you realise that his typing speed is faster than the speed you are probably thinking the solution.
@rentib9136
@rentib9136 4 жыл бұрын
I hate dp. Give me a problem on finger tree
@parthokunda
@parthokunda 4 жыл бұрын
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.
@satyampatidar5848
@satyampatidar5848 4 жыл бұрын
3×5 is not the square in red line
@Errichto
@Errichto 4 жыл бұрын
Did I claim otherwise? Timestamp please.
@jameysiddiqui6910
@jameysiddiqui6910 4 жыл бұрын
your face should be at bottom right corner and editor should be up
@user-rz8lc3zl7k
@user-rz8lc3zl7k 4 жыл бұрын
Hey brother do you read the Bible? Remember this life is only temporary
@sankarraja5709
@sankarraja5709 2 жыл бұрын
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.
First Unique Number (LeetCode Day 28)
6:48
Errichto Algorithms
Рет қаралды 21 М.
Longest Common Subsequence - Recursive and Iterative DP (LeetCode Day 26)
19:44
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 23 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 3,3 МЛН
DP 56. Count Square Submatrices with All Ones | DP on Rectangles 🔥
15:59
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
LeetCode Day 16 - Wildcards Bracket String (I Struggle)
27:35
Errichto Algorithms
Рет қаралды 29 М.
Maximal Square - Top Down Memoization - Leetcode 221
19:50
NeetCode
Рет қаралды 72 М.
LeetCode Day 15 - Product of Array Except Self
16:00
Errichto Algorithms
Рет қаралды 33 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 160 М.
Day 3 | Advent of Code 2024
13:58
Errichto Algorithms
Рет қаралды 3,2 М.
Maximal square | Dynamic programming | Leetcode #221
18:27
Techdose
Рет қаралды 72 М.
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 23 МЛН