Container With Most Water

Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.

Topic refresher: Two Pointers — Two Indices, One Rule

Move left/right based on a condition instead of checking all pairs.

int L = 0, R = n - 1;
while (L < R) {
    int sum = a[L] + a[R];
    if (sum == target) { L++; R--; }
    else if (sum < target) L++;
    else R--;
}
Two Pointers

Container With Most Water

Medium
LeetCode
2/7
MediumTwo PointersLeetCode #11

Container With Most Water

Start wide. Move the shorter wall inward — only that can improve area.

Examples

Example 1

Input

9
1 8 6 2 5 4 8 3 7

Output

49
Example 2

Input

2
1 1

Output

1

Stuck? Take a nudge

C++17