1014. Best Sightseeing Pair

Refer to maximum subarray, same logic, however the order needs to be switched so that the curr_max is read for the next iteration of the max_len

class Solution:
    def maxScoreSightseeingPair(self, values: List[int]) -> int:
        
        max_len = 0
        curr_max = values[0]-1

        for i in range(1, len(values)):
            max_len = max(max_len, curr_max+values[i])
            curr_max = max(curr_max-1, values[i]-1)
            

        return max_len

Last updated