class Solution {
public:
int maxArea(vector<int>& height) {
int i=0,j=height.size()1,ans = 0;
while(j>i)
{
ans = max(min(height[i],height[j])*(ji),ans);
if(height[i]>height[j]) j;
else i++;
}
return ans;
}
};
My short and easy c++ code in O(n)

This solution is accepted . For {3,1,1,4,1,3}, the answer should be 15 because the distance between the three's is 5 so maximum water they could hold is (3 * 5) which is 15. Read the problem carefully because to calculate the water stored two planks at indices i an j you use formulae (ji) * min(height[i],height[j]).