Problem
You get an integer array height of length n. Each item is the height of a vertical line. Line i stands at the point x = i and goes from 0 to height[i].
Pick two lines. Together with the x-axis, the two lines make a container for water. The amount of water is the distance between the lines times the height of the shorter line.
Return the largest amount of water that one container can hold. The container must stay upright.
Example 1
- Input:
- height = [2,5,3,7,4,1]
- Output:
- 12
- Explanation:
- Use the lines at indexes 1 and 4, with the heights 5 and 4. The distance is 3 and the shorter height is 4, so the amount is 12.
Example 2
- Input:
- height = [4,9]
- Output:
- 4
- Explanation:
- The only container has the distance 1 and the height 4.
Constraints
- n == height.length
- 2 <= n <= 10^5
- 0 <= height[i] <= 10^4
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Advantage Shuffle
Coding · Array · Greedy · Sorting
- Meeting Rooms II
Coding · Array · Greedy · Heap (Priority Queue)
- Valid Triangle Number
Coding · Array · Binary Search · Greedy
- Trapping Rain Water
Coding · Array · Dynamic Programming · Monotonic Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 11. Container With Most Water
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 16 records
Amazon
Container With Most Water
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 67.4. This is not an interview probability.
View sourceAmazon
Container With Most Water
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 71.5. This is not an interview probability.
View sourceAmazon
Container With Most Water
Reported date not specified · Source window: 6mo