The other answers with explanations all prove that, starting from the edge, with the moving strategy ( i.e. move the pointer of the smaller value to the inner side ), the amount of water will increase sometime in the future.

However, can the maximum value be reached? That's the key problem.

Here is my proof of why the maximum value can be reached definitely.

Given *a1, a2, ..., an.*

First of all, let's assume that the optimal choice of the container with the most water is ** ( ai, aj ) ( i < j )**. Then I just need to prove that there will definitely exist one situation where the left pointer is at

**while the right pointer is at**

*ai***.**

*aj*Then I will prove that ** a1, a2, ...and ai-1** are all smaller than

**. This proof is simple, because if**

*aj***>=**

*ak***and**

*aj***, then the optimal choice would be**

*1 <= k <= i-1***, not**

*( ak, aj )***.**

*( ai, aj )*Symmetrically, ** aj+1, aj+2, ...and an** are all smaller than

**.**

*ai*Finally, during the movement of the pointers, either ** ai** or

**will be reached at first, so let's assume**

*aj***is reached before**

*ai***. Then because**

*aj***are all smaller than**

*aj+1, aj+2, ...and an***, so the right pointer will continue moving ( because the value it points to is smaller ) until it reaches**

*ai***. Now the left pointer is at**

*aj***and the right pointer is at**

*ai***.**

*aj*And if ** aj** is reached before

**, the proof is also obvious.**

*ai*