69. Container With Most Water

MediumArrayArray

You are given an integer array height of length n. There are n vertical lines where the i-th line has height height[i]. Find two lines that together with the x-axis forms a container that holds the most water. Return the maximum amount of water that can be stored.

Input: An integer array height of length n.

Output: Integer — maximum water the container can hold.

Examples

Example 1
Input: [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: Lines at index 1 (height=8) and index 8 (height=7). Width=7, height=min(8,7)=7. Area=49.
Example 2
Input: [1,1]
Output: 1
Explanation: Only choice: min(1,1)*1=1.
Example 3
Input: [4,3,2,1,4]
Output: 16
Explanation: Lines at index 0 and 4, height=min(4,4)=4, width=4. Area=16.

Constraints

Asked by

AmazonFlipkartBloombergMicrosoftGoogleInfosys
Solve this problem in the editor →