O(n) time and O(1) memory solution
What we are interested in is maximize the value of A[i] + A[j] + i - j for i < j. \n\nLet\'s iterate the array from the left to the right and let\'s say we are 
What we are interested in is maximize the value of `A[i] + A[j] + i - j` for `i < j`. \n\nLet\'s iterate the array from the left to the right and let\'s say we are at index `j` at some moment. \nWe can easily calculate the value of `A[j] - j`. What we now need is to find out is what is the maximum value of `A[i] + i` where `i` was passed on some previous step. In order to do so, we can keep that previous maximum in a variable, which we will update at every iteration step:\n\n```\nint result = 0, n = a.length, bestPrev = 0;\nfor (int i = 0; i < n; i++) {\n  result = Math.max(result, a[i] - i + bestPrev);\n  bestPrev = Math.max(a[i] + i, bestPrev);\n}\nreturn result;\n```\n\nComplexity:\nTime: O(n)\nMemory: O(1)
[]