Back to course home
0% completed
Solution: Container With Most Water
Problem Statement
Given an array of non-negative integers, where each integer represents the height
of a vertical line positioned at index i
. You need to find the two lines that, when combined with the x-axis, form a container that can hold the most water.
The goal is to find the maximum amount of water (area) that this container can hold.
Note: The water container's width is the distance between the two lines, and its height is determined by the shorter of the two lines.
Examples
Example 1:
- Input: [1,3,2,4,5]
- Expected Output: 9
.....
.....
.....
Like the course? Get enrolled and start learning!