educative.io

Educative

Where does the /2 come from?

for(int i = 0; i < n; i++){    for(int j = 0; j < i; j++){        // constant time operations  }}

This was the only question I got wrong on the final quiz. I don’t understand where the /2 comes from.

It says the answer is n(n-1)/2. I thought you would have it over 2 if we were adding the iterator by 2 instead of one, then it would be n/2 instead of n. But that is not happening here. What is causing it to be over 2?