Given line heights, pick two lines that, together with the x-axis, hold the most water. Return that maximum area.
Start with the widest container. The shorter line limits the area, and moving the taller one inward can never help, so always move the shorter line.
1function maxArea(height: number[]): number {2let lo = 0, hi = height.length - 1, best = 0;3while (lo < hi) {4const area = (hi - lo) * Math.min(height[lo], height[hi]);5best = Math.max(best, area);6if (height[lo] < height[hi]) lo++;7else hi--;8}9return best;10}
Start with the widest pair.
Space: play/pause · ←/→: step