Leetcode 1063 Solution

This article provides solution to leetcode question 1063 (best-sightseeing-pair)

https://leetcode.com/problems/best-sightseeing-pair

Solution

class Solution:
    def maxScoreSightseeingPair(self, A: List[int]) -> int:
        if len(A) < 2:
            return 0

        ans = dp = A[0] + A[1] - 1
        for i in range(2, len(A)):
            dp = max(A[i] + A[i - 1] - 1, dp + A[i] - A[i - 1] - 1)
            ans = max(ans, dp)
        return ans