Most water between two walls
heights[i] is the height of a vertical wall standing at position i on flat ground. Pick two walls: the water between them rises only as high as the shorter one, so they hold min(heights[i], heights[j]) * (j - i) units. Walls in between do not get in the way. Return the most water any pair can hold, or 0 with fewer than two walls.
Aim for one pass with O(1) extra space.
Besides the tests, one large input (3,000 walls) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
max_water([1,8,6,2,5,4,8,3,7])→49max_water([1,1])→1max_water([4,3,2,1,4])→16