5-lines of code ✅ Easy for beginner💡 | JavaScript || Python || C++ 😎
ApproachComplexity

Time complexity: O(n)


Space complexity: O(1)

Code
# Approach
![image.png](https://assets.leetcode.com/users/images/05152ee3-e3b2-40c2-8cb0-598fa00be45c_1735268378.6140935.png)


# Complexity
- Time complexity: O(n)

- Space complexity: O(1)

# Code
```javascript []
/**
 * @param {number[]} values
 * @return {number}
 */
var maxScoreSightseeingPair = function(values) {
    let maxScore = 0;
    let maxI = values[0] + 0; //Initialize with index 0 of array

    for (let j = 1; j < values.length; j++) {
        // Calculate the score for the current pair (i, j)
        maxScore = Math.max(maxScore, maxI + values[j] - j);
        // Update maxI to include the current value and index
        maxI = Math.max(maxI, values[j] + j);
    }

    return maxScore;
};
```
```python []
class Solution(object):
    def maxScoreSightseeingPair(self, values):
        max_score = 0
        max_i = values[0]  # Initialize with values[0] + 0
        
        for j in range(1, len(values)):
            # Calculate the score for the current pair (i, j)
            max_score = max(max_score, max_i + values[j] - j)
            # Update max_i to include the current value and index
            max_i = max(max_i, values[j] + j)
        
        return max_score
```
```C++ []
class Solution {
public:
    int maxScoreSightseeingPair(vector<int>& values) {
        int maxScore = 0;
        int maxI = values[0]; // Initialize with values[0] + 0

        for (int j = 1; j < values.size(); j++) {
            // Calculate the score for the current pair (i, j)
            maxScore = max(maxScore, maxI + values[j] - j);
            // Update maxI to include the current value and index
            maxI = max(maxI, values[j] + j);
        }

        return maxScore;
    }
};
```
['Array', 'Dynamic Programming', 'Python', 'C++', 'JavaScript']