LeetCode solutions

1063. Best Sightseeing Pair

My accepted Python solution to LeetCode problem 1063, Best Sightseeing Pair, running in 68ms.

  • Difficulty: Medium
  • Python
  • Runtime 68ms
  • Memory 23.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 68ms, memory 23.2MB, accepted 2026-01-02.

python
class Solution:
    def maxScoreSightseeingPair(self, values: List[int]) -> int:
        # Score = values[i] + i + values[j] - j
        # Keep track of max(values[i] + i) seen so far
        max_i = values[0] + 0  # values[i] + i for first element
        result = 0
        
        for j in range(1, len(values)):
            # Current score with best previous i
            result = max(result, max_i + values[j] - j)
            # Update max_i
            max_i = max(max_i, values[j] + j)
        
        return result

Source