Python3 easy to understand solution in one pass.
The max score is defined as A[i] + A[j] + i - j, and the only constraint is i < j.\nInstead of directly comuting the score, we can find the solution by separate
The max score is defined as `A[i] + A[j] + i - j`, and the only constraint is `i < j`.\nInstead of directly comuting the score, we can find the solution by separate `i` and `j`.\n\n1. We maintain the maximum of `A[i] + i` for all previous visited spots\n2. We sum the maximum of `A[i] + i` with current spot `A[j]`, which is `A[i] + i + A[j] - j]`. We also maintain this value, which will become the final max score after iteration over the entire array.\n\n```py\n    def maxScoreSightseeingPair(self, A: List[int]) -> int:\n        best_i = 0\n        res = 0\n        for i, v in enumerate(A):\n            # here v - i is actually `A[j] - j` in the formula\n            res = max(res, v - i + best_i)\n            # here we store `A[i] + i`\n            best_i = max(best_i, v + i)\n        return res\n```
['Python']