Container With Most Water
MediumArrays & Strings
Given an array of integers height where height[i] represents the height of a vertical line at position i, find two lines that together with the x-axis form a container that holds the most water.
Example:
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: Lines at index 1 (height 8) and index 8 (height 7)
form a container of width 7 and height 7 → area = 49
Constraints:
- •
2 <= height.length <= 10^5 - •
0 <= height[i] <= 10^4
Container With Most Water
MediumArrays & Strings
Given an array of integers height where height[i] represents the height of a vertical line at position i, find two lines that together with the x-axis form a container that holds the most water.
Example:
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: Lines at index 1 (height 8) and index 8 (height 7)
form a container of width 7 and height 7 → area = 49
Constraints:
- •
2 <= height.length <= 10^5 - •
0 <= height[i] <= 10^4
Press Run or Ctrl+Enter to execute