educative.io

Double checking upper bound of for loop

I have question about this code
for (int i = 0; i < arr.size() - 2; i++) {
count += searchPair(arr, target - arr[i], i);
}

Why do we use arr.size() - 2 as upper bound of loop?

‘i’ is the left most pointer, then we have ‘left’ and ‘right’ pointers, so we want the ‘i’ pointer to stop before the end leaving to spots for ‘left’ and ‘right’ pointers, otherwise they will be out of bounds

I agree this is somewhat poor naming, i would call ‘i’ as ‘left’ and ‘left’ as ‘mid’, more intuitive imho…