# Container with Most Water

• When updating the shorter line, no need to check the area until a larger line is found...

• when both pointer have same height which one to move?

• I think there is a bug, when both pointer have same height, and test cases of Leetcode don't detect that.

• If both pointers have the same height, giving up anyone is fine...

• This is very strange but the solution above returns TLE when submitted. Is this a bug in LeetCode test running system? It has happened with me twice.

• If the heights are float numbers instead of integer, does the two pointer solution still work?

• if both are same, you should move both pointers i.e. l++, r--

• the above code is not giving the same area when the input height list is passed in a reverse order. For example, height lists [14, 5, 4] and [4, 5, 14] should give the same max Area formed by the two extreme lines(4, 14) separated by 2 units. The max area is 8. [14,5,4] gives 8 but [4, 5,14] gives 5. Don't you think this is a bug?

• I am doing in python, here is the code-

``````class Solution(object):
def maxArea(self, height):
l = 0
r=len(height)-1
res=0
while l < r:
area= min(height[l],height[r]*(r-l))
res = max(res, area)
if height[l] < height[r]:
l+= 1
else:
r -= 1
return res
``````

• Sorry, I was doing the mistake, it should be
min(height[l],height[r]) * (r-l), I was multiplying (r-l) only for second parameter.

• O( N log(N) ) passed though.

• two pointer is awesome!

• THIS IS NOT PROGRAMMING. THIS IS RIDDLE

• when i use #1 run int array {1,2,3...14999,15000},the result is 56250000,but the result is 14999 when i use #2,it is mean that #2 not inclue all the combination

• I've never come across a problem of this type before. I wanted to solve it on my own without looking at hints or solution, but couldn't crack it on my own after trying for 40 minutes. Finally gave up and looked at the solution which is pretty simple, surprised why I did not think in this line. Is there anything I can do to improve my problem solving skills, especially the ones which are completely new?

• the description of the problem not descriptive and clear !

• very clear solution!

• I just don't get what this question ask...=。=

• @sireesh I think the best way to get better with this type of problem solving is to learn the techniques, in this case the two pointer technique. Keep it in the back of your mind every single future question, and compile a list of problems you couldn't solve the first time and the techniques in the solution. Eventually, most problems will looks like variations of previous problems. Good luck! (p.s. it's a tough road, but we're all in this together :) )

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.