Leetcode 11. Container With Most Water

11. Container With Most Water

Implication : If we move the higher side inside, the area must be smaller.

Reference Solution

class Solution:
    def maxArea(self, height: List[int]) -> int:
        lo = 0
        hi = len(height) - 1
        maxArea = 0
        # Implication : If we move the higher side inside, the area must be smaller.
        while lo < hi :
            if (height[lo] < height[hi]) :
                maxArea = max(maxArea, height[lo] * ( hi - lo ))
                lo += 1
            else :
                maxArea = max(maxArea, height[hi] * ( hi - lo ))
                hi -= 1
                
        return maxArea