Maximize Two Sight Values Minus Their Index Distance
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Choose two different positions i<j in `values`. Their score is `values[i]+values[j]+i-j`, combining both values and subtracting their index distance. Return the largest pair score.
```cpp
class Solution {
public:
int maxScoreSightseeingPair(vector<int>& values);
};
```
### Examples
**Example 1:**
```text
Input: values = [4,7,2]
Output: 10
Explanation: Pair(0,1) scores4+7-1=10; the other two pairs score4 and8.
```
**Example 2:**
```text
Input: values = [2,2]
Output: 3
Explanation: The only pair scores2+2-1=3.
```
### Constraints
- `2 <= values.length <= 5*10^4`.
- `1 <= values[i] <= 1000`.
### Contract considerations
The result is a maximum score; the source does not ask for the maximizing indices.
```hint Read the boundary condition
Separate the expression into one term depending only on i and one depending only on j.
```
### Boundary reminders
The result is a maximum score; the source does not ask for the maximizing indices.
Overview: Maximize Two Sight Values Minus Their Index Distance. Choose two different positions i<j in values.
Maximize Two Sight Values Minus Their Index Distance
Google
Aug 29, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Choose two different positions i<j in values. Their score is values[i]+values[j]+i-j, combining both values and subtracting their index distance. Return the largest pair score.
class Solution {
public:
int maxScoreSightseeingPair(vector<int>& values);
};
Examples
Example 1:
Input: values = [4,7,2]
Output: 10
Explanation: Pair(0,1) scores4+7-1=10; the other two pairs score4 and8.
Example 2:
Input: values = [2,2]
Output: 3
Explanation: The only pair scores2+2-1=3.
Constraints
2 <= values.length <= 5*10^4
.
1 <= values[i] <= 1000
.
Contract considerations
The result is a maximum score; the source does not ask for the maximizing indices.
Boundary reminders
The result is a maximum score; the source does not ask for the maximizing indices.