Problems/

Container With Most Water

medium

You are given an integer array height of length n. There are n vertical lines such that the two endpoints of the i-th line are (i, 0) and (i, height[i]).

Find two lines that, together with the x-axis, form a container that holds the most water, and return that maximum area.

The area between lines i and j is (j - i) * min(height[i], height[j]) — water can't rise above the shorter line.

Example 1

Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: lines at indices 1 and 8 give (8-1) * min(8,7) = 49.

Example 2

Input: height = [1,1]
Output: 1

Constraints

  • 2 <= height.length <= 100000
  • 0 <= height[i] <= 10000

Input

height = [1,8,6,2,5,4,8,3,7]

Expected

49

5 hidden tests run on submit