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

Sdílet
Vložit
  • čas přidán 24. 07. 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

Komentáře • 68

  • @radioactivepotato4078
    @radioactivepotato4078 Před 7 měsíci +16

    dude you're so underrated , this channel deserves to be more famous.

  • @jritzeku
    @jritzeku Před 7 měsíci +8

    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  Před 7 měsíci +5

      I try to make sure that I go over the problem and how to solve rather than focus on coding

  • @bobbysokhi7296
    @bobbysokhi7296 Před 8 dny

    This was a really fun problem and your explanation actually made it so much easier to implement. Thank you.

  • @sevenscapes
    @sevenscapes Před 5 měsíci

    Wohoo🔥! The best explanation that I have ever found on the Internet. Way to GO🚀🚀

  • @saisree04
    @saisree04 Před 2 měsíci +2

    Amazing explanation, and they way u explained the solution using a diagram is simply amazing. Thank You

  • @safar19899
    @safar19899 Před rokem +2

    Great explanation. Thank you!

  • @crazyshorts4890
    @crazyshorts4890 Před dnem

    Wonderful session ever session through visualisation ❤❤❤
    Thank you so much

  • @Akash-Bisariya
    @Akash-Bisariya Před rokem +2

    Awesome bro, thanks for the explanation.

  • @ritikasingh6298
    @ritikasingh6298 Před 15 dny

    Thankyou so much you made building logic so easy !

  • @nikithaponamma646
    @nikithaponamma646 Před 3 měsíci +1

    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  Před 3 měsíci

      Glad you liked it!

  • @shubhamWork-ji3em
    @shubhamWork-ji3em Před 2 měsíci

    Thanks bro, understood the concept so well have coded it without seeing your solution and both the code looks same :)

  • @pcccmn
    @pcccmn Před 10 měsíci +6

    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 Před 5 měsíci

    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.

  • @sahil00234
    @sahil00234 Před měsícem

    keep it up bro you got our back

  • @mattaniamckoy3774
    @mattaniamckoy3774 Před 11 měsíci

    Thank you! Your explanation was very clear and easy to follow.

    • @nikoo28
      @nikoo28  Před 10 měsíci

      You are welcome!

  • @Harshitha-dj1ps
    @Harshitha-dj1ps Před 3 měsíci

    howww comee soo perfectt all the time!! we love you sir,wish we had solution for every question from you!! YOUUU AREE JUSTTT BESTTT!!

  • @jashanjotbedi1796
    @jashanjotbedi1796 Před 6 měsíci +1

    Nicely explained .

  • @chiruchiruchiranjeevi3237

    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  Před 11 měsíci

      all the very best for your placements :)

  • @hoddybhaba6704
    @hoddybhaba6704 Před rokem

    Easy to understand..👏👏👏

  • @Steve_Nice
    @Steve_Nice Před 8 měsíci

    Thanks, I had a hard time understanding this one but you made is super clear

    • @nikoo28
      @nikoo28  Před 7 měsíci

      You're very welcome!

  • @sharaabsingh
    @sharaabsingh Před rokem +3

    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  Před rokem +2

      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 Před rokem +1

      @@nikoo28 Sure!! Will do

  • @chrisdan81
    @chrisdan81 Před 6 měsíci

    Most accurate explanation

  • @apex095
    @apex095 Před rokem +2

    Great explanation. Could you also please make a video for solving "Trapping rain water" leetcode problem ?

  • @anupamahalder4792
    @anupamahalder4792 Před 4 měsíci +1

    Nice explanation

  • @trinitykhuman
    @trinitykhuman Před 7 měsíci +1

    Best explaination

  • @raziuddin2081
    @raziuddin2081 Před 2 měsíci

    such deep explaination......Thanks

  • @srishti6637
    @srishti6637 Před 11 měsíci

    tahnk u so much. The best explanation ever.

  • @MsProtestante
    @MsProtestante Před rokem

    brilliant!

  • @anukulsahu
    @anukulsahu Před 8 měsíci +1

    Gud explanation

  • @surajsidar3280
    @surajsidar3280 Před měsícem

    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

  • @parthmodi2028
    @parthmodi2028 Před 6 měsíci

    Great Explaination. keep kaing videos vro

    • @nikoo28
      @nikoo28  Před 6 měsíci

      A new video every week 😄

  • @kapiltanwer552
    @kapiltanwer552 Před 6 měsíci +1

    nice video

  • @parthanuj8611
    @parthanuj8611 Před rokem +1

    love your voice

  • @cognizant2474
    @cognizant2474 Před 6 měsíci

    Thanku :)

  • @itsmesam1774
    @itsmesam1774 Před 6 měsíci +1

    edge case -
    both right and left stick are equal toy do l++ and r--

  • @jayprakashjaiswaldeptofcom1250

    hey bro your explanation is fucking awesome ,please dont stop to upload video in future and please upload more video,and thanks

  • @Not_First_Of_His_Name
    @Not_First_Of_His_Name Před měsícem

    great

  • @user-hk2bu4nn6g
    @user-hk2bu4nn6g Před 4 měsíci

    What will happen if both left and right are equal in length ? Then moving any one pointer will potentially create a problem ?

  • @CPS_XI
    @CPS_XI Před 4 měsíci

    ❤💯

  • @jayprakashjaiswaldeptofcom1250

    and bro can u make video on Aggressive Cows problem ,i am not able to understand question only

  • @santoshkumargouda6033

    Please make a seeies on sliding windows problems

  • @ramakrishnakcr4417
    @ramakrishnakcr4417 Před 4 měsíci

    🤩

  • @garvitarora2413
    @garvitarora2413 Před 6 měsíci

    What if both are equal(left pointer and right pointer value equal) then what should be done ??

    • @nikoo28
      @nikoo28  Před 5 měsíci

      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.

  • @rohitsaka
    @rohitsaka Před 2 lety +1

    ⚡️

  • @user-jg7eb3xt9q
    @user-jg7eb3xt9q Před 10 měsíci

    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  Před 9 měsíci

      if you can justify the updates, then it is good.

  • @abdulaleem4407
    @abdulaleem4407 Před 2 lety +2

    Can you please explain me what is the logic behind this greedy spin game
    How it’s played

    • @nikoo28
      @nikoo28  Před 2 lety +2

      What do you mean by the greedy spin game? Can you dm me? The details are in the channel info section

    • @abdulaleem4407
      @abdulaleem4407 Před 2 lety +1

      @@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 Před 2 lety

      @@nikoo28
      Where should I contact you
      I have some photos of that I will send

    • @nikoo28
      @nikoo28  Před 2 lety

      Please check the channel info section. You will find my email address.

  • @dipendupaul
    @dipendupaul Před 11 měsíci

    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  Před 10 měsíci

      a recursive solution is usually harder to debug in my opinion.

  • @ojaskumar2355
    @ojaskumar2355 Před 4 měsíci

    Every time i come here for solution, i realize how dumb i'm.

  • @AadeshKulkarni
    @AadeshKulkarni Před 5 měsíci +1

    Baba you're beautiful!

    • @nikoo28
      @nikoo28  Před 5 měsíci +2

      are chitvan...tune programming kab shuru kar di

    • @AadeshKulkarni
      @AadeshKulkarni Před 5 měsíci +1

      @@nikoo28 Jabse aapne DSA sikhaana shuru kar diya baba! Beautiful! 🫡

  • @sadvikMoravineni
    @sadvikMoravineni Před 3 dny

    you are the besttt🥲🥲🥲😭😭😭😭 i love you Math.pow(3,1000);