LeetCode Container With Most Water Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

I think you should put more effort into explanations by getting a white board or something...you just type out the code

ucheanonyai
Автор

Done thanks
Two pointers, start off at the edges, move the pointer inward of the smaller edge. Doesn’t need to be O(n^2) because once u start off at the edges, no matter what you do, the width will always be decreasing (you started off at the edges so you have to move inwards) the only way to get a bigger area is if you keep the largest of the two edges you’re at and try to find an edge that will give u a greater area.

mostinho
Автор

This is amazing Nick...very simple to understand, your explanation made this question look really simple. Nice

somyasrivastava
Автор

great explanation Nick!!, just one question, why we do not consider betn index 1 to index 6 : height of 1. so what I mean is the answer should be 49 + 4 = 53. because betn 8 and 8 their is still a bar if height 1 we can fill. and now it becomes max.

munjal
Автор

well done Nick! Publish more solutions pls!!

georgechen
Автор

Thank you for the vids Nick, they really help 🙏

nerodant
Автор

once again nick bro explaining the problem and approach very clearly.

Thanks nick brother u help me alot in learning these concepts and approaches

satyamgupta
Автор

Why are you not checking else if(height[bpointer] < height[apointer]) instead just else, because if add a else condition am getting a timeoutexception and not sure why on leetcode

InfoBuzz
Автор

How do we know pointers are at idx 0 and len(height)? Is it possible to get a working solution w/ i = 0, j + 1. If not, why? Thanks!

ricocode
Автор

hey, is this a same problem as the largest histogram, if yes then why the solution this can't apply it to largest histogram pr and it didn't work?why?

jagdishwarbiradar
Автор

What is the difference b/w this Q and *Largest Rectangle in Histogram* ?

sayantaniguha
Автор

How do you handle the case when the heights of a_pointer and b_pointer are same? Does it not matter which pointer we move in such a case?

dhawaldhingra
Автор

You haven't explained the intuition behind the solution, rather you have memorized the solution and regurgitated without understanding it. You also have an unnecessary repetition of the calculation of max_area, it can be done just once outside of the if statement.

thatguy
Автор

Hi dont understand why we use small pointer.

lifeofme
Автор

Why does sliding window not work here?

alitherland
Автор

This is my solution, python version:

def
if len(container) == 0 or len(container) == 1:
return 0
min_ht = min(given[0], given[1])
max_vol = min_ht * 1
for step in range(2, len(container)):
for i in range(step):
min_ht = min(given[i], given[step])
vol = min_ht * (step-i)
if max_vol < vol:
max_vol = vol
return max_vol

jugsma
Автор

Lmao damn, and here i was trying to use branch n bound ...

erictsang
Автор

why he have written bpointer - apointer pls someone tell.

damudaran
Автор

That what happens when you memorize the solution and vomit it out without thinking.
and even though u solved it one hour ago, first try failed. Grow up dude

therahulgoeltravel
Автор

What is the difference b/w this Q and *Largest Rectangle in Histogram* ?

sayantaniguha