var maxScoreSightseeingPair = function (values) {
let max = 0,
i = 0,
j = 1
while (i < j && j < values.length) {
const sp = values[i] + values[j] - (j - i)
if (sp > max) {
max = sp
}
if (values[i] + i < values[j] + j) {
i = j
}
j++
}
return max
}
console.log(maxScoreSightseeingPair([7, 2, 6, 6, 9, 4, 3]))
var maxScoreSightseeingPair = function (values) {
let first = values[0] + 0
let max = 0
for (let j = 1; j < values.length; j++) {
const second = values[j] - j
const current = first + second
max = Math.max(max, current)
first = Math.max(first, values[j] + j)
}
return max
}