Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Container With Most Water

Problem can be found in here!

Solution: Two Pointers

def maxArea(heights: List[int]) -> int:
    max_volumne = 0
    left, right = 0, len(heights)-1
    while left < right:
        height, width = min(heights[left], heights[right]), right-left
        max_volumne = max(max_volumne, height*width)
        if heights[left] >= heights[right]:
            while left < right and height >= height[right]:
                right -= 1
        else:
            while left < right and height >= height[left]:
                left += 1

    return max_volumne

Explanation: Please refer to link for explanation.

Time Complexity: O(n), Space Complexity: O(1)