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

ความคิดเห็น • 64

  • @radioactivepotato4078
    @radioactivepotato4078 6 หลายเดือนก่อน +15

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

  • @jritzeku
    @jritzeku 7 หลายเดือนก่อน +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 หลายเดือนก่อน +4

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

  • @sevenscapes
    @sevenscapes 4 หลายเดือนก่อน

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

  • @safar19899
    @safar19899 ปีที่แล้ว +2

    Great explanation. Thank you!

  • @saisree04
    @saisree04 2 หลายเดือนก่อน +2

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

  • @Akash-Bisariya
    @Akash-Bisariya 11 หลายเดือนก่อน +2

    Awesome bro, thanks for the explanation.

  • @pcccmn
    @pcccmn 10 หลายเดือนก่อน +5

    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

  • @ritikasingh6298
    @ritikasingh6298 6 วันที่ผ่านมา

    Thankyou so much you made building logic so easy !

  • @hoddybhaba6704
    @hoddybhaba6704 ปีที่แล้ว

    Easy to understand..👏👏👏

  • @shubhamWork-ji3em
    @shubhamWork-ji3em หลายเดือนก่อน

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

  • @chrisdan81
    @chrisdan81 6 หลายเดือนก่อน

    Most accurate explanation

  • @jashanjotbedi1796
    @jashanjotbedi1796 6 หลายเดือนก่อน +1

    Nicely explained .

  • @nikithaponamma646
    @nikithaponamma646 3 หลายเดือนก่อน +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  2 หลายเดือนก่อน

      Glad you liked it!

  • @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.

  • @sahil00234
    @sahil00234 27 วันที่ผ่านมา

    keep it up bro you got our back

  • @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!!

  • @mattaniamckoy3774
    @mattaniamckoy3774 11 หลายเดือนก่อน

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

    • @nikoo28
      @nikoo28  10 หลายเดือนก่อน

      You are welcome!

  • @apex095
    @apex095 ปีที่แล้ว +2

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

  • @raziuddin2081
    @raziuddin2081 2 หลายเดือนก่อน

    such deep explaination......Thanks

  • @trinitykhuman
    @trinitykhuman 6 หลายเดือนก่อน +1

    Best explaination

  • @anupamahalder4792
    @anupamahalder4792 4 หลายเดือนก่อน +1

    Nice explanation

  • @Steve_Nice
    @Steve_Nice 8 หลายเดือนก่อน

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

    • @nikoo28
      @nikoo28  7 หลายเดือนก่อน

      You're very welcome!

  • @chiruchiruchiranjeevi3237
    @chiruchiruchiranjeevi3237 11 หลายเดือนก่อน +2

    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 :)

  • @MsProtestante
    @MsProtestante ปีที่แล้ว

    brilliant!

  • @anukulsahu
    @anukulsahu 8 หลายเดือนก่อน +1

    Gud explanation

  • @srishti6637
    @srishti6637 11 หลายเดือนก่อน

    tahnk u so much. The best explanation ever.

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน

      So nice of you

  • @sharaabsingh
    @sharaabsingh ปีที่แล้ว +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  ปีที่แล้ว +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 ปีที่แล้ว +1

      @@nikoo28 Sure!! Will do

  • @itsmesam1774
    @itsmesam1774 5 หลายเดือนก่อน +1

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

  • @surajsidar3280
    @surajsidar3280 หลายเดือนก่อน

    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

  • @cognizant2474
    @cognizant2474 5 หลายเดือนก่อน

    Thanku :)

  • @parthanuj8611
    @parthanuj8611 11 หลายเดือนก่อน +1

    love your voice

  • @kapiltanwer552
    @kapiltanwer552 6 หลายเดือนก่อน +1

    nice video

  • @jayprakashjaiswaldeptofcom1250
    @jayprakashjaiswaldeptofcom1250 ปีที่แล้ว

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

  • @parthmodi2028
    @parthmodi2028 6 หลายเดือนก่อน

    Great Explaination. keep kaing videos vro

    • @nikoo28
      @nikoo28  5 หลายเดือนก่อน

      A new video every week 😄

  • @Not_First_Of_His_Name
    @Not_First_Of_His_Name 21 วันที่ผ่านมา

    great

  • @CPS_XI
    @CPS_XI 3 หลายเดือนก่อน

    ❤💯

  • @rohitsaka
    @rohitsaka 2 ปีที่แล้ว +1

    ⚡️

  • @ramakrishnakcr4417
    @ramakrishnakcr4417 4 หลายเดือนก่อน

    🤩

  • @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 ปีที่แล้ว

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

  • @garvitarora2413
    @garvitarora2413 6 หลายเดือนก่อน

    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.

  • @abdulaleem4407
    @abdulaleem4407 2 ปีที่แล้ว +2

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

    • @nikoo28
      @nikoo28  2 ปีที่แล้ว +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 ปีที่แล้ว +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 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 11 หลายเดือนก่อน

    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  10 หลายเดือนก่อน

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

  • @user-jg7eb3xt9q
    @user-jg7eb3xt9q 10 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

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

  • @ojaskumar2355
    @ojaskumar2355 3 หลายเดือนก่อน

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

  • @AadeshKulkarni
    @AadeshKulkarni 5 หลายเดือนก่อน +1

    Baba you're beautiful!

    • @nikoo28
      @nikoo28  5 หลายเดือนก่อน +2

      are chitvan...tune programming kab shuru kar di

    • @AadeshKulkarni
      @AadeshKulkarni 5 หลายเดือนก่อน +1

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