The problem. You are given an array height where height[i] is the height of a vertical wall at position i. Pick two walls; together with the ground they form a container. Return the most water a container can hold. The water level stops at the shorter wall, so the amount is min(height[i], height[j]) × (j − i).
Input: height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output: 49 walls 1 and 8: min(8, 7) × (8 − 1) = 49
Input: height = [1, 1]
Output: 1Two forces pull against each other: width wants the walls far apart, and height wants both walls tall. Walls between the chosen two don't matter at all — they don't block the water.
Free account
Sign up to read the rest of this lesson: 5 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come