DSA Visualizer · 25 visualizationsContainer With Most Water
Arrays & Hashing
Two SumValid AnagramContains DuplicateGroup AnagramsTop K Frequent ElementsProduct of Array Except SelfLongest Consecutive SequenceStack
Valid ParenthesesBinary Search
Binary SearchTrees & BFS
Binary Tree Level OrderGraphs
Number of IslandsTrees
Invert Binary TreeMediumTwo Pointers
Container With Most Water
You are given an integer array height of length n. Find two lines that, together with the x-axis, form a container that holds the most water. Return the maximum amount of water a container can store.
The step-through player is coming for this one. Two Sum has the full animation today; the rest are being authored in the admin.
Pythontime O(n) · space O(1)
def maxArea(height: list[int]) -> int:
l, r = 0, len(height) - 1
best = 0
while l < r:
best = max(best, min(height[l], height[r]) * (r - l))
if height[l] < height[r]: l += 1
else: r -= 1
return bestNext upTrapping Rain Water
Two Sum is free. Enroll to unlock every visualization and save where you stopped.Enroll free
Watch the video walkthrough