Facebook Pixel
Container With Most Water
Medium

Given an integer array height where height[i] represents the height of a vertical line at index i, find two lines that together with the x-axis form a container that holds the most water. Return the maximum amount of water a container can store.

Example:

Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The best container is formed between the second (height = 8) and last (height = 7) vertical lines, storing 49 units of water.
Test Cases

Test Cases

Input
1 8 6 2 5 4 8 3 7
Expected Output
49
Step 1
Step 2
Step 3
Step 4
Step 1: Identify the Pattern
Container With Most Water
Medium

Given an integer array height where height[i] represents the height of a vertical line at index i, find two lines that together with the x-axis form a container that holds the most water. Return the maximum amount of water a container can store.

Example:

Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The best container is formed between the second (height = 8) and last (height = 7) vertical lines, storing 49 units of water.
Test Cases

Test Cases

Input
1 8 6 2 5 4 8 3 7
Expected Output
49
Step 1
Step 2
Step 3
Step 4
Step 1: Identify the Pattern