← Practice · Two pointers

Container With Most Water Medium

You are given an array height where height[i] is the height of a vertical line at x = i. Pick two lines that, with the x-axis, form a container holding the most water. Return that maximum area (width times the shorter height).

Examples

  • [1,8,6,2,5,4,8,3,7] -> 49
  • [1,1] -> 1

Define a function named maxArea in JavaScript.

00:00▶ Visualize

JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests