With a simple rewrite of the expression, everything becomes clear
Rewrite (A[i] + A[j] + i - j) as (A[i] + i) + (A[j] - j), where i < j.\n\nFor each element A[j], you want to know the largest (A[i] + i) to its left because tha
Rewrite `(A[i] + A[j] + i - j)` as `(A[i] + i) + (A[j] - j)`, where `i < j`.\n\nFor each element `A[j]`, you want to know the largest `(A[i] + i)` to its left because that maximises the value of  `(A[i] + i) + (A[j] - j)` for the current `A[j]`. We use a variable to remember the largest `A[i] + i` seen so far.\n    \nAlso, if  the value of `(A[i] + i) + (A[j] - j)`  for this `A[j]` is higher than the highest seen before, we update the current high score. We use another variable to remember the largest `(A[i] + i) + (A[j] - j)` seen so far.\n    \n```\nclass Solution {\n    public int maxScoreSightseeingPair(int[] A) {\n        // the greatest (A[i] + i) we\'ve seen so far which is A[0] + 0, but + 0 is redundant\n        int max_i = A[0];     \n        // the high score we want to return\n        int high_score = Integer.MIN_VALUE;\n        \n        for (int j = 1; j < A.length; ++j) {\n            // check if adding this (A[j] - j) increases the current high score\n            high_score = Math.max(high_score, max_i + A[j] - j);\n            // update the largest (A[i] + i) seen so far\n            max_i = Math.max(max_i, A[j] + j);\n        }\n        \n        return high_score;\n    }\n}\n```
[]