aboutsummaryrefslogtreecommitdiff
path: root/best_sightseeing_pair.py
diff options
context:
space:
mode:
Diffstat (limited to 'best_sightseeing_pair.py')
-rw-r--r--best_sightseeing_pair.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/best_sightseeing_pair.py b/best_sightseeing_pair.py
new file mode 100644
index 0000000..7fecb66
--- /dev/null
+++ b/best_sightseeing_pair.py
@@ -0,0 +1,29 @@
+# 1014. Best Sightseeing Pair
+
+"""
+you are given an integer array 'values' where 'values[i]' represents the
+value of the i'th sightseeing spot. two sightseeing spots 'i' and 'j' have a
+distance 'j - i' between them. the score of a pair ('i < j') of sightseeing
+spots is 'values[i] + values[j] + i - j': the sum of the values of the
+sightseeing spots. minus the distance between them. return the maximum score
+of a pair of sightseeing spots.
+"""
+
+
+class Solution(object):
+ def maxScoreSightseeingPair(self, values):
+ """
+ :type values: List[int]
+ :rtype: int
+ """
+ ans, curr = 0, 0
+ for i in values:
+ ans = max(ans, curr + i)
+ curr = max(curr, i) - 1
+ return ans
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.maxScoreSightseeingPair(values=[8, 1, 5, 2, 6]))
+ print(obj.maxScoreSightseeingPair(values=[1, 2]))