Container With Maximum Water (LeetCode 11) | Full Solution with Visuals | Study Algorithms
ฝัง
- เผยแพร่เมื่อ 15 ก.ค. 2024
- You are given an array of positive integers that represents sticks of different heights. These sticks can form several different containers of varying areas. This video talks about how you can visualize a problem first to make it easier to solve and understand. Eventually, you need to find out the maximum area of a container possible. Work along with me to see how it can be solved easily along with the dry-run of code in JAVA.
Chapters:
00:00 - Intro
01:09 - Problem Statement and Description
04:16 - Simplify with visualization
05:15 - Solution Container with Maximum Water
09:20 - Dry-run of Code
11:32 - Final Thoughts
Actual problem on LeetCode: leetcode.com/problems/contain...
📚 Links to topics I talk about in the video:
Time Complexity: • What is the Time Compl...
What is Big O?: • Big O Notation Simplif...
LeetCode Problems: • Leetcode Solutions
Data Structures: • Data Structures
📘 A text based explanation is available at: studyalgorithms.com/array/con...
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/36pU0JO
Favorite book to understand algorithms: amzn.to/39w3YLS
Favorite book for data structures: amzn.to/3oAVBTk
Get started for interview preparation: amzn.to/39ysbkJ
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3pAqh8O
Microphone: amzn.to/2MCX7qU
Recording Camera: amzn.to/3alg9Ky
Tablet to sketch and draw: amzn.to/3pM6Bi4
Surface Pen: amzn.to/3pv6tTs
Laptop to edit videos: amzn.to/2LYpMqn
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#interview #programming #leetcode
dude you're so underrated , this channel deserves to be more famous.
What separates you apart from others is that you really take time to explain the problem and solutions WITHOUT jumping to code too quickly. Also the visual aids are legible and easy to follow. By the time you've finished explanation, the coding part actually becomes simple. I was able to do the water area problem without even looking at your code. You have a gift of teaching...keep it up!
I try to make sure that I go over the problem and how to solve rather than focus on coding
Wohoo🔥! The best explanation that I have ever found on the Internet. Way to GO🚀🚀
Great explanation. Thank you!
Amazing explanation, and they way u explained the solution using a diagram is simply amazing. Thank You
Awesome bro, thanks for the explanation.
I think many people got stuck at this problem because they don't know WHEN to move the LEFT and RIGHT pointers. The "Medium" tag on this question is from the maths involved. Not much from the two pointers
Thankyou so much you made building logic so easy !
Easy to understand..👏👏👏
Thanks bro, understood the concept so well have coded it without seeing your solution and both the code looks same :)
Most accurate explanation
Nicely explained .
What a great explanation! Even if your video is 1 hour long, I would watch it without skipping ahead :) Please continue to make such amazing content 🎉
Glad you liked it!
brilliant explaination, i already submitted this question.. but I was trying to find a good youtuber who can explain the problem with the most popular solution and its reasoning.. and in almost every video on YT guys are jumping into the logic of moving smaller height because its the best case already. But none said the point that we are starting from the widest width and will trying to reduce the width but you said that. That made you stand apart. will be watching all your videos now.
keep it up bro you got our back
howww comee soo perfectt all the time!! we love you sir,wish we had solution for every question from you!! YOUUU AREE JUSTTT BESTTT!!
Thank you! Your explanation was very clear and easy to follow.
You are welcome!
Great explanation. Could you also please make a video for solving "Trapping rain water" leetcode problem ?
such deep explaination......Thanks
Best explaination
Nice explanation
Thanks, I had a hard time understanding this one but you made is super clear
You're very welcome!
as soon as i see tht if my problem is on ur channel, i'm pretty sure that by the end of the video i would be capable of solving that.. just palying major role for my my placements brother THANKYOUSOMUCHHHHH...
all the very best for your placements :)
brilliant!
Gud explanation
tahnk u so much. The best explanation ever.
So nice of you
Dude, did anyone tell you that you are simply amazing!! Thank you so much for such a wonderful explanation. The way you visualized the problem is hands down the best I found anywhere. Kudos to all the hard work you put in
Wow, thank you! This really means a lot to me. If possible share this content with your friends wherever possible. Costs you nothing...but keeps me motivated :D
@@nikoo28 Sure!! Will do
edge case -
both right and left stick are equal toy do l++ and r--
I am watching this video after the interview.
This was asked to me.
I was not able to answer how I was moving two pointers.
I was confused at that time.
I got the answer after watching the video:
We have to find minimum of left and right heights
To utilize a larger height better we have to move the pointer pointer to a smaller height.
We have to keep storing the max area in some variable to find maximum water container
Thanku :)
love your voice
nice video
hey bro your explanation is fucking awesome ,please dont stop to upload video in future and please upload more video,and thanks
Great Explaination. keep kaing videos vro
A new video every week 😄
great
❤💯
⚡️
🤩
What will happen if both left and right are equal in length ? Then moving any one pointer will potentially create a problem ?
and bro can u make video on Aggressive Cows problem ,i am not able to understand question only
What if both are equal(left pointer and right pointer value equal) then what should be done ??
You can move either the left pointer or the right pointer inwards. It doesn't matter which one you choose because the area will be the same as the width (the difference between the indices) would be reduced by one, and the height remains the same.
Can you please explain me what is the logic behind this greedy spin game
How it’s played
What do you mean by the greedy spin game? Can you dm me? The details are in the channel info section
@@nikoo28
Sir it's betting game on some vegetables we have to bit a coin After spin roll and the result will appear
How the result will come what is the logic behind that
@@nikoo28
Where should I contact you
I have some photos of that I will send
Please check the channel info section. You will find my email address.
When analyzing the line at the left index, why do we only need to consider lines between [left + 1, right] and not the lines beyond? The reason is lines between [first...left - 1] have a perfect in [right ... last]; similarly, lines between [right + 1... left] have a perfect in [start... left], and that's the reason when analyzing line at the left index we only need to consider lines between [left + 1, right]. So in effect, we have a sub-problem, P(left, right), similar, to the original problem, P(first, last). Recursive solution would be much more intuitive.
a recursive solution is usually harder to debug in my opinion.
What if the condition of updation of l and r be like..-
if(height[l+1] >= height[r-1]) l++;
else r--;
It is working but is it a correct logic??
if you can justify the updates, then it is good.
Every time i come here for solution, i realize how dumb i'm.
Baba you're beautiful!
are chitvan...tune programming kab shuru kar di
@@nikoo28 Jabse aapne DSA sikhaana shuru kar diya baba! Beautiful! 🫡