Container With Most Water

Given an array of positive integers `height` representing heights, find two lines which together with the x-axis forms a container and return the maximum amount of water the container can hold.

Input Format

height = array of positive integers representing line heights

Output Format

maximum area of water that can be contained

Constraints

Examples

Example 1:

Input:

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

Output:

49

Explanation:

Container between lines at index 1 (height 8) and index 8 (height 7) holds 7 * (8 - 1) = 49.

Example 2:

Input:

height = [1,1]

Output:

1

Explanation:

Only possible container holds 1 * (1 - 0) = 1.

Example 3:

Input:

height = [4,3,2,1,4]

Output:

16

Explanation:

Container between lines at index 0 and 4 holds 4 * (4 - 0) = 16.

Loading...
Container With Most Water - Two Pointers