# [Container with most water](https://leetcode.com/problems/container-with-most-water/) ###### tags: `Leetcode`, `Medium`, `Two Pointers` ## Approach * Initialize two pointers `left` and `right` to `0` and `len(height) - 1` * Initialize *max_area = 0* * Calculate *current_area* as follows: ``` current_area = min(height[left], height[right]) * (right - left) ``` * Calculate *max_area* as `max(max_area, current_area)` * If left height is less than right height, increment left by 1 * If right height is less then left height, decrement right by 1 ## Asymptotic Analysis ### Time Complexity: **O(N)** ### Space Complexity: **O(1)** ## Code ``` python from typing import List class ContainerWithMostWater: @staticmethod def max_area(height: List[int]) -> int: maximum_area = 0 left, right = 0, len(height) - 1 while left < right: area = min(height[left], height[right]) * (right - left) maximum_area = max(maximum_area, area) if height[left] < height[right]: left += 1 else: right -= 1 return maximum_area heights = [1, 8, 6, 2, 5, 4, 8, 3, 7] print(ContainerWithMostWater.max_area(heights)) ```