Easy Python | O(n) Time, O(1) Space
Easy Python | O(n) Time, O(1) Space\n\nTo maximize the formula "A[i]+i+A[j]-j", we can note that for any index "j", the score is maximized by the best value of 
**Easy Python | O(n) Time, O(1) Space**\n\nTo maximize the formula "A[i]+i+A[j]-j", we can note that for any index "j", the score is maximized by the best value of "A[i]+i" seen before (since "A[j]-j" is fixed). As a result, we can make a one-pass O(n) loop remembering only the highest value of "A[i]+i" in O(1) space, and update the record score that we observe (variable "best").\n\nI hope the explanation was helpful. Cheers,\n\n```\nclass Solution:\n    def maxScoreSightseeingPair(self, A) :\n        K    = A[0]\n        best = float(\'-inf\')\n        for j in range(1,len(A)):\n            x    = A[j]\n            best = max(best, K + x - j )\n            K    = max(K   , x + j     )\n        return best\n```
['Python', 'Python3']