402. Container With Most Water
MediumTwo Pointers
Line i has height a[i]. Choose two lines that, with the x-axis, hold the most water. Print that amount: min(a[i], a[j]) × (j − i).
Input format
Line 1: n Line 2: n heights
Output format
The maximum area.
Example 1
Input
9 1 8 6 2 5 4 8 3 7
Output
49
Example 2
Input
2 1 1
Output
1
Constraints
2 ≤ n ≤ 10⁵ 0 ≤ a[i] ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…