One important observation is, value of (arr[i] – i) – (arr[j] – j) can never be negative. We can alway swap i and j to convert a negative value into positive. So the condition i not equal to j is bogus and doesn’t require explicit check.