11. Container With Most Water
My accepted Python solution to LeetCode problem 11, Container With Most Water, running in 111ms.
- Difficulty: Medium
- Python
- Runtime 111ms
- Memory 27.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 111ms, memory 27.6MB, accepted 2025-12-29.
class Solution:
def maxArea(self, height: List[int]) -> int:
left, right = 0, len(height) - 1
max_area = 0
while left < right:
width = right - left
h = min(height[left], height[right])
max_area = max(max_area, width * h)
if height[left] < height[right]:
left += 1
else:
right -= 1
return max_area