Because when n is very large, the value of n*(n+1) will overflow. You can judge whether it is odd or accidental and then do the division first.
Note this sentence: You may assume the result will be in the range of 32-bit signed integer.
The requirement is that your result will be in the range of 32-bit signed integer. . Assume that the result of n*(n+1)/2 just meets 32 bits. But before doing the division
the result of n*(n+1) exceeds 32 bits.