Thoughts on 1014
The final output can be divided into two parts values[i] + i and values[j] - j
we need to update the maximum value for values[i] + i in each iteration and calculate the output for that certain index
Solution for 1014
https://leetcode-cn.com/problems/best-sightseeing-pair/
class Solution {
public int maxScoreSightseeingPair(int[] values) {
int max = Integer.MIN_VALUE;
int output = 0;
for(int i = 0; i < values.length; i++){
output = Math.max(max + values[i] - i, output);
max = Math.max(max, values[i] + i);
}
return output;
}
}