Why does two pointers find the answer? Suppose the answer is at indices and with . Initially, and .
Every time you move right, it's because the current sum is too small. Since the array is sorted, the correct index must be further right.
So you never skip past . Similarly, you never skip past when moving left. Eventually, and .