Compute the maximum water trapped by a pair of vertical lines
ContainerWithMostWater.java
public static int getMaxArea(List<Integer> heights) {
int i = 0, j = heights.size() - 1;
int res = 0;
while (i < j) {
res = Math.max(res, Math.min(heights.get(i), heights.get(j)) * (j - i));
if (heights.get(i) > heights.get(j)) {
--j;
} else if (heights.get(i) < heights.get(j)) {
++i;
} else { // heights[i] == heights[j].
++i;
--j;
}
}
return res;
}