1014. Best Sightseeing Pair ¶ Time: Space: C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12 13 14class Solution { public: int maxScoreSightseeingPair(vector<int>& values) { int ans = 0; int bestPrev = 0; for (const int value : values) { ans = max(ans, value + bestPrev); bestPrev = max(bestPrev, value) - 1; } return ans; } }; 1 2 3 4 5 6 7 8 9 10 11 12 13class Solution { public int maxScoreSightseeingPair(int[] values) { int ans = 0; int bestPrev = 0; for (final int value : values) { ans = Math.max(ans, value + bestPrev); bestPrev = Math.max(bestPrev, value) - 1; } return ans; } } 1 2 3 4 5 6 7 8 9 10class Solution: def maxScoreSightseeingPair(self, values: list[int]) -> int: ans = 0 bestPrev = 0 for value in values: ans = max(ans, value + bestPrev) bestPrev = max(bestPrev, value) - 1 return ans