Let me simplify this for those who still find it confusing . We know that water container is a rectangle so area will be simply lxb = area so either we need to increase the length or the breadth to maximise the area . Placing the pointer at two ends creates maximises the length now the interesting part if you move any of the two pointer then you are reducing the length so to balance it you must increase the breadth(height) . There are two pointer pointing to two different height now obviously we need to move that pointer which has less height among the two and we move the pointer unless it finds a height that is greater than its previous value and then calculates the area and store . This proces is repeated to calculate the max area . Hope it helps 🙂
Sab koi sirf two pointer two pointer chilla rahe hai... aapne hi clear kar diya ke kyo hum un cases ko ignore karenge. Mazza a gaya. Ab confidence hai aur koi ratne ki zaroorat nai.
I have seen tons of videos, all I could find is code and complexity discussion, however I could not visualize how they came up with the code and why to reduce particular pointer. This is the best video I have seen so far which made me visualize what is actually happening in detail. Great job. Superb explanation. Please make more videos on Hard/Medium Problems of LC.
Agreed! This is the best video on this particular problem. Clearly explained why we could ignore the other possibilities when we move the pointer. Great Work!
00:00 The key point is to maximize water volume in containers with different heights by calculating differences and exploring various possibilities for optimal solutions. 05:12 Exploring various scenarios to maximize area calculation by considering different heights and possibilities. 10:24 Ignoring certain cases in problem-solving can save time and lead to better results. Maximizing area by comparing height and length is crucial for efficiency in solving problems.
idhar udhar baat ghumaaye bina sateek samghaya hai. Thanks a lot sir!!! Kyu chote wale ko aage badha rahe main yhi smaghna tha aur wo aapne acche se samghaya.
I comment rarely on Yoututbe..Trust me You did the Best Explaination.. I followed the same approach of using two for looops and when u said about that in video ,i was totally suprised... and your way of explaination for O(n) is awesome...
if we are doing len = r-1 then one test case is not passing ,instead we should use (r-l) more optimised code will be -- class Solution { public: int maxArea(vector& height) {
int l = 0; int r = height.size()-1; int maxi = 0; if( height.size() ==2 ) { maxi = min(height[l],height[r])*r; } while(l
very clear explanation. code in python :- class Solution: def maxArea(self, height: List[int]) -> int: l = 0 r = len(height) - 1 max_area = 0 while(l max_area: max_area = area # print(max_area) if height[l] < height[r] : # we are doing this as right is greater than left so we will move to left to right to get max value area l +=1 else: r -= 1 return max_area
see basically left will be moved till it finds a line greater than the right and vice versa right will be moved till it finds a line greater than left as a result min of left right is taken and mul with the length.(tip-area=l*b(or h)) therefore as L decrease h should increase
Bhiya, bohot best explanation hai, phod dia, thanks... Mai 1st time is channel par aai hu or 💯 satisfaction mila. superb explanation... Dimag mai ghusa dia concept... Aap ko kabhi bolne ki jaroorat nhi padegi - "channel subscribe karo", aapke content kii quality awesome hai
thanks. I was thinking of why moving the pointer for smaller height is equivalent to checking all answers and you cleared my remaining doubt. When moving from outside to inside, the span reduces anyway, we hope to find a taller height wall by considering a different wall from the smaller of the two at a time.
Maza agaya.. Thank you so much . Last time ratta mara tha.. chalo finally feeling better ki understood the logic.. Thank you for the amazing content.. from now i better look leetcode questions from your channel only..Thank you..
This video is amazing! The way you explained the solution , sir, it was so beginner friendly, easy to understand, easy to visualise and all the reasons for selecting a particular move, perfectly explained. I have seen so many coding solution videos, but THIS IS THE BEST TILL NOW! BIG THANKS!
Everytime, we are moving our pointer i ahead if height of line at ith index is smaller or j pointer if height of line at jth index is smaller. This means whichever line is smaller, we won’t consider it again, because, this line could be the answer only if the other line is larger than it and at maximum width and to be noticed that this is the time when other line is larger as well as max distance apart. So, not considering it makes sense.
literally i just watched only 2:25 min and i solved that without seeing solution 😍.. coz of directly clear explanation.. waht this question want to say 💜🖤...
This is one of the best explanation I have ever found.. Excellent job! Automatically became a subscriber and looking forward for more insightful videos!!!
Let me simplify this for those who still find it confusing . We know that water container is a rectangle so area will be simply lxb = area so either we need to increase the length or the breadth to maximise the area . Placing the pointer at two ends creates maximises the length now the interesting part if you move any of the two pointer then you are reducing the length so to balance it you must increase the breadth(height) . There are two pointer pointing to two different height now obviously we need to move that pointer which has less height among the two and we move the pointer unless it finds a height that is greater than its previous value and then calculates the area and store . This proces is repeated to calculate the max area . Hope it helps 🙂
I read your comment before watching videos . understood the solution by seeing your comment. Asowme explanation bro
Thank you!
after reading your comment i didnt even need to watch the video
Sab koi sirf two pointer two pointer chilla rahe hai... aapne hi clear kar diya ke kyo hum un cases ko ignore karenge. Mazza a gaya. Ab confidence hai aur koi ratne ki zaroorat nai.
I have seen tons of videos, all I could find is code and complexity discussion, however I could not visualize how they came up with the code and why to reduce particular pointer. This is the best video I have seen so far which made me visualize what is actually happening in detail. Great job. Superb explanation. Please make more videos on Hard/Medium Problems of LC.
Thank you.
means a lot
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
Agreed! This is the best video on this particular problem. Clearly explained why we could ignore the other possibilities when we move the pointer. Great Work!
00:00
The key point is to maximize water volume in containers with different heights by calculating differences and exploring various possibilities for optimal solutions.
05:12
Exploring various scenarios to maximize area calculation by considering different heights and possibilities.
10:24
Ignoring certain cases in problem-solving can save time and lead to better results. Maximizing area by comparing height and length is crucial for efficiency in solving problems.
Itne badhiya se samjha diya bhai apne to, Thank you brother :)
Stuck on the explanation for half an hour. Glad I found this video!
idhar udhar baat ghumaaye bina sateek samghaya hai. Thanks a lot sir!!! Kyu chote wale ko aage badha rahe main yhi smaghna tha aur wo aapne acche se samghaya.
I comment rarely on Yoututbe..Trust me You did the Best Explaination..
I followed the same approach of using two for looops and when u said about that in video ,i was totally suprised...
and your way of explaination for O(n) is awesome...
if we are doing len = r-1 then one test case is not passing ,instead we should use (r-l)
more optimised code will be --
class Solution {
public:
int maxArea(vector& height) {
int l = 0;
int r = height.size()-1;
int maxi = 0;
if( height.size() ==2 )
{
maxi = min(height[l],height[r])*r;
}
while(l
very clear explanation.
code in python :-
class Solution:
def maxArea(self, height: List[int]) -> int:
l = 0
r = len(height) - 1
max_area = 0
while(l max_area:
max_area = area
# print(max_area)
if height[l] < height[r] :
# we are doing this as right is greater than left so we will move to left to right to get max value area
l +=1
else:
r -= 1
return max_area
Thanks...I really enjoyed your explanation..you are spending more time to explain logic rather than code ..That is awesome man...
Awesome explanation and visualisation, after watching your explanation, I wrote the code by myself, crystal clear video. Maza aa gaya.
The best channel to understand this problem, you have portrayed a medium level problem to a easy problem.
i was struggling for the entire day trying to figure out why we use two pointers, finally peace. thank you so much!!
You seriously struggled the whole day for this question? I thought I was alone ! Heheh high 5 buddy!!!
@@ayeshaadhikari6123 yeah. just need to keep practicing and you'll finally be able to solve any type of Q
One of the best tutorials ever I had seen on this platform
great explanation, forward to 05:50 for saving time
Best explanation till now for this question. Thank you so much sir
Easiest explanation of this problem that anyone can ever find.
Bhai approach smjhi or code likha , 1st attempt m hi hogya ..... Thanks for such a beautiful explanation 👏
Best leetcode solution of this problem on youTube.
Thank you.
Appreciate it.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
Thank you for explaining the most confusing part. No doubt best explanation for this particular question. God Bless you!!
see basically left will be moved till it finds a line greater than the right and vice versa right will be moved till it finds a line greater than left as a result min of left right is taken and mul with the length.(tip-area=l*b(or h)) therefore as L decrease h should increase
your way of explanation is easy and clear thanks a lot for this amazing solution video
sir pls make series of leetcode questions on dp sir.Thanks for beautiful solution
Already uploaded.
Thank you.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
Bhiya, bohot best explanation hai, phod dia, thanks...
Mai 1st time is channel par aai hu or 💯 satisfaction mila. superb explanation...
Dimag mai ghusa dia concept...
Aap ko kabhi bolne ki jaroorat nhi padegi - "channel subscribe karo", aapke content kii quality awesome hai
Nice explaination bhai, mein samajh hi nahi paa raha tha sirf solution padh ke. Superb.
thanks. I was thinking of why moving the pointer for smaller height is equivalent to checking all answers and you cleared my remaining doubt.
When moving from outside to inside, the span reduces anyway, we hope to find a taller height wall by considering a different wall from the smaller of the two at a time.
we can make it more faster. if we keep doing left++ or right-- untill we find the greater height than the min height.
bohot jyada clear and crisp explanation tha bhay!!!
Best explaination ever ! you got one more subscriber :)
great explaination, so easy to understand, thank you so much
Maza agaya.. Thank you so much . Last time ratta mara tha.. chalo finally feeling better ki understood the logic.. Thank you for the amazing content.. from now i better look leetcode questions from your channel only..Thank you..
sir to mera liye god ha sach me..... thanks a lot
Clear and crisp explanation
lots of love brother. subscribed!!☺
You should make more videos sir 🥺🥺 abhi tak kisi ne itne ache se ni smjhaya hai dsa .. pleaaaaaaaase make more videosssss
the best explaination of a problem I've ever got on youtube, you're best in expressing your thoughts. great job!
This video is amazing! The way you explained the solution , sir, it was so beginner friendly, easy to understand, easy to visualise and all the reasons for selecting a particular move, perfectly explained. I have seen so many coding solution videos, but THIS IS THE BEST TILL NOW! BIG THANKS!
absolutely loved the explaination.....
not all superheroes wear a cape!
explanation couldn't get better, thanks
Best ever explanation in youtube
crisp and sweet sir.....
Bhaiji..aap videos bhut h dil se banate ho..I always learn a lot from your videos.
Thank you so much..:)
meine vaise hi kiya tha jaise aapne pehle bataya(two pointers), time limit exceed ho gayi🥲
Aapne bhot hi well samjhaya h..Thanks Sir...Hare Krishna..
Beautifully explained !! This was really crystal clear explanation !!!
Great explanation.Aap great hai.
Amazing explanation! To the point and explains the intuition behind the problem very accurately! LOVED IT!
Nice brother for explaining it so easily
Simple and sorted explaination
thanks sie , you explained it with very op method
but don't know why the code giving me TLE
Bhai yaa to apka mic god level h ya to aawaz me dum h..you sound like a RJ
wow, 10:02 👌👌👌👌
Thank you.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
Your explanation is helpful but also so funny I'm cracking up hahahahaha
Great Sir , I hit the jackpot in the first go.......
Thank you so much sir
Everytime, we are moving our pointer i ahead if height of line at ith index is smaller or j pointer if height of line at jth index is smaller. This means whichever line is smaller, we won’t consider it again, because, this line could be the answer only if the other line is larger than it and at maximum width and to be noticed that this is the time when other line is larger as well as max distance apart. So, not considering it makes sense.
nice explanation sir....
Keep watching.
Thank you.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
Sir you are best teacher
literally i just watched only 2:25 min and i solved that without seeing solution 😍.. coz of directly clear explanation.. waht this question want to say 💜🖤...
Great explanation
Wow what an amazing video! I was struggling a lot with this one ,thanks anyway.
literally very neat and clean explanation i was confused in this question after watching this concept ....... all clear
thankss sirr! it cannot be this simple
Best 2 pointer explanation
Thank you sir
Most welcome
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
superbbbbb brother loved the explanation ..
bhai great 👍
Thank you brother for amazing approach , this is the best video on youtube for this question
thanks brother.....
This is one of the best explanation I have ever found.. Excellent job! Automatically became a subscriber and looking forward for more insightful videos!!!
Thanks a lot sir, it helps a lot. Please make more videos like this🙏🙏
Thanks it was great
Wow very helpful video sir
ty bhai god bless u
bhot badiya explanation hai sir
The best explanation for this problem...Thanks:)
Thank you.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
you nailed it bro
the best explanation. Next level. Thank u so much !!!
Thanks a lot 🙏
Thank you sir for explanation ............
Impressive explanation!!!!!!!!!!!!
Great Explanation sir.....!!! Keep making more videos like this and helping us in understanding concepts very well.😊. Thanks again, sir.
This is the best video explanation for this problem on YT I can bet. Thanks a lot. @CodeBix please upload more videos on medium problems.
Man!! best explaination out there. Keep up the good work!!
Appreciate it.
Follow our linkedin page for regular updates www.linkedin.com/company/codebix/?viewAsMember=true
I was asked this question on Goldman Sachs interview and couldn't come up with this solution.
you earned a new subscriber!!
crazy explanation!! you earned a sub
Thank you bhaiya nice explaination
very well explaination brother thank you so much
Nicely Explained
👩🎓too good explanation.
Very nice explanation.
nice explaination
Nice explanation 😮 😀
Great explanation bro !!
thank you so much
you explain every question so well🙌
thank you, sir nice explanation
you literally rocked it too good explaination loved it :)
Best explanation. Keep making such videos. You got sub + 1 :)