The idea is that a container to hold water can only be formed by two two heights with the lowest height as the height of the container. So, if we start from two numbers farthest apart in length (i.e. first and last element) then we have maximum width rectangle. Now, we can move to shorter height only to left or right to maximize the total area.

```
public class Solution {
public int maxArea(int[] height) {
int len = height.length, low = 0, high = len -1 ;
int maxArea = 0;
while (low < high) {
maxArea = Math.max(maxArea, (high - low) * Math.min(height[low], height[high]));
if (height[low] < height[high]) {
low++;
} else {
high--;
}
}
return maxArea;
}
}
```