Skip to interview prep
Apexed

35. Container With Most Water

MediumTwo pointers

height[i] is the height of a vertical line at position i. Pick two lines that, with the x-axis, hold the most water. Return that maximum area (width × the shorter height).

Example 1

Input: height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output: 49

Constraints

  • 2 ≤ height.length ≤ 10⁵

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Container With Most Water — coding interview practice — Apexed