Optimized Python 3 Solution for Container with most water problem.
I am using two pointer shifting technique to solve it so that we can reduce time complexity of the solution.
CODE:-
class Solution:
def maxArea(self, height: List[int]) -> int:
maxArea = 0
p1 = 0
p2 = len(height)-1
while(p1<=p2):
maxArea = max(maxArea,min(height[p1],height[p2])*(p2-p1))
if(height[p1]<height[p2]):
p1=p1+1
else:
p2=p2-1
return maxArea
Top comments (0)