#1014

Best Sightseeing Pair

specialist · 665 · lc medium +30 · verified · 62.7% accepted · 3,284 likes · top 64%

Description

An integer array values describes sightseeing spots. The score of a pair of spots (i, j) with i < j is values[i] + values[j] + i - j.

Return the maximum score of any such pair.

Example 1:

Input: values = [8,1,5,2,6]
Output: 11
Explanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11

Example 2:

Input: values = [1,2]
Output: 2

Code

1
2
3