Container With Maximum Water (LeetCode 11) | Full Solution with Visuals | Study Algorithms

  Рет қаралды 18,608

Nikhil Lohia

Nikhil Lohia

Күн бұрын

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

Пікірлер: 63
@radioactivepotato4078
@radioactivepotato4078 6 ай бұрын
dude you're so underrated , this channel deserves to be more famous.
@jritzeku
@jritzeku 6 ай бұрын
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!
@nikoo28
@nikoo28 6 ай бұрын
I try to make sure that I go over the problem and how to solve rather than focus on coding
@saisree04
@saisree04 Ай бұрын
Amazing explanation, and they way u explained the solution using a diagram is simply amazing. Thank You
@sevenscapes
@sevenscapes 4 ай бұрын
Wohoo🔥! The best explanation that I have ever found on the Internet. Way to GO🚀🚀
@pcccmn
@pcccmn 10 ай бұрын
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
@shauryasingh2212
@shauryasingh2212 4 ай бұрын
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.
@safar19899
@safar19899 Жыл бұрын
Great explanation. Thank you!
@surajsidar3280
@surajsidar3280 23 күн бұрын
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
@Akash-Bisariya
@Akash-Bisariya 11 ай бұрын
Awesome bro, thanks for the explanation.
@shubhamWork-ji3em
@shubhamWork-ji3em Ай бұрын
Thanks bro, understood the concept so well have coded it without seeing your solution and both the code looks same :)
@nikithaponamma646
@nikithaponamma646 2 ай бұрын
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 🎉
@nikoo28
@nikoo28 2 ай бұрын
Glad you liked it!
@Harshitha-dj1ps
@Harshitha-dj1ps 3 ай бұрын
howww comee soo perfectt all the time!! we love you sir,wish we had solution for every question from you!! YOUUU AREE JUSTTT BESTTT!!
@apex095
@apex095 Жыл бұрын
Great explanation. Could you also please make a video for solving "Trapping rain water" leetcode problem ?
@mattaniamckoy3774
@mattaniamckoy3774 10 ай бұрын
Thank you! Your explanation was very clear and easy to follow.
@nikoo28
@nikoo28 9 ай бұрын
You are welcome!
@chiruchiruchiranjeevi3237
@chiruchiruchiranjeevi3237 11 ай бұрын
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...
@nikoo28
@nikoo28 11 ай бұрын
all the very best for your placements :)
@jashanjotbedi1796
@jashanjotbedi1796 6 ай бұрын
Nicely explained .
@sahil00234
@sahil00234 16 күн бұрын
keep it up bro you got our back
@sharaabsingh
@sharaabsingh 11 ай бұрын
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
@nikoo28
@nikoo28 11 ай бұрын
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
@sharaabsingh
@sharaabsingh 11 ай бұрын
@@nikoo28 Sure!! Will do
@hoddybhaba6704
@hoddybhaba6704 Жыл бұрын
Easy to understand..👏👏👏
@chrisdan81
@chrisdan81 5 ай бұрын
Most accurate explanation
@Steve_Nice
@Steve_Nice 7 ай бұрын
Thanks, I had a hard time understanding this one but you made is super clear
@nikoo28
@nikoo28 6 ай бұрын
You're very welcome!
@raziuddin2081
@raziuddin2081 Ай бұрын
such deep explaination......Thanks
@anupamahalder4792
@anupamahalder4792 3 ай бұрын
Nice explanation
@itsmesam1774
@itsmesam1774 5 ай бұрын
edge case - both right and left stick are equal toy do l++ and r--
@trinitykhuman
@trinitykhuman 6 ай бұрын
Best explaination
@anukulsahu
@anukulsahu 7 ай бұрын
Gud explanation
@srishti6637
@srishti6637 10 ай бұрын
tahnk u so much. The best explanation ever.
@nikoo28
@nikoo28 10 ай бұрын
So nice of you
@MsProtestante
@MsProtestante Жыл бұрын
brilliant!
@user-hk2bu4nn6g
@user-hk2bu4nn6g 3 ай бұрын
What will happen if both left and right are equal in length ? Then moving any one pointer will potentially create a problem ?
@jayprakashjaiswaldeptofcom1250
@jayprakashjaiswaldeptofcom1250 Жыл бұрын
hey bro your explanation is fucking awesome ,please dont stop to upload video in future and please upload more video,and thanks
@parthanuj8611
@parthanuj8611 11 ай бұрын
love your voice
@parthmodi2028
@parthmodi2028 6 ай бұрын
Great Explaination. keep kaing videos vro
@nikoo28
@nikoo28 5 ай бұрын
A new video every week 😄
@kapiltanwer552
@kapiltanwer552 6 ай бұрын
nice video
@jayprakashjaiswaldeptofcom1250
@jayprakashjaiswaldeptofcom1250 Жыл бұрын
and bro can u make video on Aggressive Cows problem ,i am not able to understand question only
@cognizant2474
@cognizant2474 5 ай бұрын
Thanku :)
@Not_First_Of_His_Name
@Not_First_Of_His_Name 11 күн бұрын
great
@garvitarora2413
@garvitarora2413 5 ай бұрын
What if both are equal(left pointer and right pointer value equal) then what should be done ??
@nikoo28
@nikoo28 5 ай бұрын
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.
@CPS_XI
@CPS_XI 3 ай бұрын
❤💯
@user-jg7eb3xt9q
@user-jg7eb3xt9q 9 ай бұрын
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??
@nikoo28
@nikoo28 8 ай бұрын
if you can justify the updates, then it is good.
@rohitsaka
@rohitsaka 2 жыл бұрын
⚡️
@ramakrishnakcr4417
@ramakrishnakcr4417 3 ай бұрын
🤩
@abdulaleem4407
@abdulaleem4407 2 жыл бұрын
Can you please explain me what is the logic behind this greedy spin game How it’s played
@nikoo28
@nikoo28 2 жыл бұрын
What do you mean by the greedy spin game? Can you dm me? The details are in the channel info section
@abdulaleem4407
@abdulaleem4407 2 жыл бұрын
@@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
@abdulaleem4407
@abdulaleem4407 2 жыл бұрын
@@nikoo28 Where should I contact you I have some photos of that I will send
@nikoo28
@nikoo28 2 жыл бұрын
Please check the channel info section. You will find my email address.
@dipendupaul
@dipendupaul 10 ай бұрын
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.
@nikoo28
@nikoo28 9 ай бұрын
a recursive solution is usually harder to debug in my opinion.
@ojaskumar2355
@ojaskumar2355 3 ай бұрын
Every time i come here for solution, i realize how dumb i'm.
@AadeshKulkarni
@AadeshKulkarni 5 ай бұрын
Baba you're beautiful!
@nikoo28
@nikoo28 4 ай бұрын
are chitvan...tune programming kab shuru kar di
@AadeshKulkarni
@AadeshKulkarni 4 ай бұрын
@@nikoo28 Jabse aapne DSA sikhaana shuru kar diya baba! Beautiful! 🫡
Alat Seru Penolong untuk Mimpi Indah Bayi!
00:31
Let's GLOW! Indonesian
Рет қаралды 14 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 58 МЛН
Deepwater's Gene Munster on why Google will win the AI arms race
7:29
B+ tree in database | Introduction & Example | DBMS  | Bhanu Priya
10:40
The BETTER Raspberry Pi? // ZimaBlade Review
13:41
Christian Lempa
Рет қаралды 10 М.
Container with Most Water - Leetcode 11 - Python
12:37
NeetCode
Рет қаралды 297 М.