O(n) time and O(1) space solution
Intuition/ApproachKeep track of a value, as we move through the array, the value decreases.
At each index, the score will be the tracked value plus the value at
# Intuition/Approach
Keep track of a value, as we move through the array, the value decreases.
At each index, the score will be the tracked value plus the value at index.
If a value is found that is greater than the tracked value then use it.
# Complexity
- Time complexity: O(n)
- Space complexity: O(1)
# Code
```python []
class Solution(object):
  def maxScoreSightseeingPair(self, values):
    max_score = 0
    score = values[0]
    for i in range(1, len(values)):
      score -= 1
      if (score + values[i] > max_score):
        max_score = score + values[i]
      if (values[i] > score):
        score = values[i]
    return max_score
        
```
```cpp []
class Solution {
public:
  int maxScoreSightseeingPair(vector<int>& values) {
    int max = 0, score = values[0];
    for (int i = 1; i < values.size(); ++i) {
      --score;
      if (score + values[i] > max) max = score + values[i];
      if (values[i] > score) score = values[i];
    }
    return max;
  }
};
```
```java []
class Solution {
  public int maxScoreSightseeingPair(int[] values) {
    int max = 0, score = values[0];
    for (int i = 1; i < values.length; ++i) {
      --score;
      if (score + values[i] > max) max = score + values[i];
      if (values[i] > score) score = values[i];
    }
    return max;
  }
}
```
```c []
int maxScoreSightseeingPair(int* values, int valuesSize) {
  int max = 0, score = *values; 
  for (++values, --valuesSize; valuesSize; ++values, --valuesSize) {
    --score;
    if (score + *values > max) max = score + *values;
    if (*values > score) score = *values;
  }
  return max;
}
```
```python3 []
class Solution:
  def maxScoreSightseeingPair(self, values: List[int]) -> int:
    max_score = 0
    score = values[0]
    for i in range(1, len(values)):
      score -= 1
      if (score + values[i] > max_score):
        max_score = score + values[i]
      if (values[i] > score):
        score = values[i]
    return max_score
        
```
```csharp []
public class Solution {
  public int MaxScoreSightseeingPair(int[] values) {
    int max = 0, score = values[0];
    for (int i = 1; i < values.Length; ++i) {
      --score;
      if (score + values[i] > max) max = score + values[i];
      if (values[i] > score) score = values[i];
    }
    return max;
  }
}
```
```javascript []
/**
 * @param {number[]} values
 * @return {number}
 */
var maxScoreSightseeingPair = function(values) {
  let max = 0, score = values[0];
  for (let i = 1; i < values.length; ++i) {
    --score;
    if (score + values[i] > max) max = score + values[i];
    if (values[i] > score) score = values[i];
  }
  return max;
};
```
```typescript []
function maxScoreSightseeingPair(values: number[]): number {
  let max = 0, score = values[0];
  for (let i = 1; i < values.length; ++i) {
    --score;
    if (score + values[i] > max) max = score + values[i];
    if (values[i] > score) score = values[i];
  }
  return max;
};
```
weird languages
```php []
class Solution {
  /**
    * @param Integer[] $values
    * @return Integer
    */
  function maxScoreSightseeingPair($values) {
    $max = 0;
    $score = $values[0];
    $length = count($values);
    for ($i = 1; $i < $length; ++$i) {
      --$score;
      if ($score + $values[$i] > $max) $max = $score + $values[$i];
      if ($values[$i] > $score) $score = $values[$i];
    }
    return $max;
  }
}
```
```swift []
class Solution {
  func maxScoreSightseeingPair(_ values: [Int]) -> Int {
    var max = 0, score = values[0];
    for i in 1..<values.count {
      score -= 1;
      if (score + values[i] > max) {
        max = score + values[i];
      }
      if (values[i] > score) {
        score = values[i];
      }
    }
    return max;
  }
}
```
```kotlin []
class Solution {
  fun maxScoreSightseeingPair(values: IntArray): Int {
    var max = 0
    var score = values[0]
    for (i in 1..<values.size) {
      score -= 1
      if (score + values[i] > max) max = score + values[i]
      if (values[i] > score) score = values[i]
    }
    return max
  }
}
```
```dart []
class Solution {
  int maxScoreSightseeingPair(List<int> values) {
    int max = 0, score = values[0];
    for (int i = 1; i < values.length; ++i) {
      --score;
      if (score + values[i] > max) max = score + values[i];
      if (values[i] > score) score = values[i];
    }
    return max;
  }
}
```
```golang []
func maxScoreSightseeingPair(values []int) int {
    max := 0;
    score := values[0];
    for i := 1; i < len(values); i++ {
      score--;
      if (score + values[i] > max) {
        max = score + values[i];
      }
      if (values[i] > score) {
        score = values[i];
      }
    }
    return max;
}
```
```ruby []
# @param {Integer[]} values
# @return {Integer}
def max_score_sightseeing_pair(values)
  max = 0
  score = values[0]
  for i in 1 ... values.length()
    score -= 1
    if (score + values[i] > max); max = score + values[i] end
    if (values[i] > score); score = values[i] end
  end
  return max;
end
```
```scala []
object Solution {
  def maxScoreSightseeingPair(values: Array[Int]): Int = {
    var max = 0;
    var score = values(0);
    for (i <- 1 to (values.length - 1)) {
      score -= 1;
      if (score + values(i) > max) max = score + values(i);
      if (values(i) > score) score = values(i);
    }
    return max;
  }
}
```
```rust []
impl Solution {
  pub fn max_score_sightseeing_pair(values: Vec<i32>) -> i32 {
    let mut max = 0;
    let mut score = values[0];
    for i in 1..values.len() {
      score -= 1;
      if (score + values[i] > max) { max = score + values[i] }
      if (values[i] > score) { score = values[i] }
    }
    return max;
  }
}
```
delinquent languages
```elixir []
defmodule Solution do
  def max_score_sightseeing_pair(values) do
    [first | rest] = values
    rest
    |> Enum.reduce({0, first, 1}, fn value, {max, score, i} ->
      score = score - 1
      new_max = max(max, score + value)
      new_score = max(score, value)
      {new_max, new_score, i + 1}
    end)
    |> elem(0)
  end
end
```
```erlang []
-spec max_score_sightseeing_pair(Values :: [integer()]) -> integer().
  max_score_loop([], Max, _, _) -> Max;
  max_score_loop([Value | Rest], Max, Score, I) ->
    NewScore = Score - 1,
    NewMax = max(Max, NewScore + Value),
    NextScore = max(NewScore, Value),
    max_score_loop(Rest, NewMax, NextScore, I + 1).
  max_score_sightseeing_pair(Values) -> [First | Rest] = Values, max_score_loop(Rest, 0, First, 1).
```

['Swift', 'C', 'PHP', 'Python', 'C++', 'Java', 'TypeScript', 'Rust', 'JavaScript', 'C#']