O25
Container With Most Water
Problem Statement & Objective
You are given an integer array height of length n. There are n vertical lines drawn 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, such that the container contains the most water. Return the maximum amount of water a container can store.
Function Signature (Python)
max_water_container(heights: list[int]) -> intInput & Output Contract
Output Rule:Maximum water area integer.
System Constraints
n == height.length
2 <= n <= 10^5
0 <= height[i] <= 10^4Example Execution Walkthrough
height = [1,8,6,2,5,4,8,3,7]
lines at index 1 (height 8) and index 8 (height 7) give area = min(8, 7) * (8 - 1) = 7 * 7 = 49Example Test Scenarios (3)
Example 1
Input:
[[1,8,6,2,5,4,8,3,7]]Expected Output:
49Example 2: İki Duvar
Input:
[[1,1]]Expected Output:
1Example 3: Symmetric Duvarlar
Input:
[[4,3,2,1,4]]Expected Output:
16