Doubt regarding

why we used n-2 and n-1 in this code