11. Container With Most Water

Tapan RachchhTapan Rachchh
1 min read
class Solution:
    def maxArea(self, height: List[int]) -> int:
        x = 0
        l = len(height)
        y = l - 1
        maxWater = 0


        for gap in range(l - 1, 0, -1):
            xVal = height[x]
            yVal = height[y]
            water = min(xVal, yVal) * gap

            if water > maxWater:
                maxWater = water
            if xVal < yVal:
                x += 1
            else:
                y -= 1

        return maxWater
0
Subscribe to my newsletter

Read articles from Tapan Rachchh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tapan Rachchh
Tapan Rachchh