From 27c5cf0dd6b7b34932bb361adda3fe619b08512f Mon Sep 17 00:00:00 2001 From: Siddhartha Dutta Date: Sun, 29 Dec 2024 15:17:42 +0000 Subject: [PATCH] Dec 27 --- .../Best Sightseeing Pair.py | 22 +++++++++++++++++++ .../README.md | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 2024-12-December-LeetCoding-Challenge/Best Sightseeing Pair.py diff --git a/2024-12-December-LeetCoding-Challenge/Best Sightseeing Pair.py b/2024-12-December-LeetCoding-Challenge/Best Sightseeing Pair.py new file mode 100644 index 0000000..471845f --- /dev/null +++ b/2024-12-December-LeetCoding-Challenge/Best Sightseeing Pair.py @@ -0,0 +1,22 @@ +from typing import List + + +class Solution: + def maxScoreSightseeingPair(self, values: List[int]) -> int: + max_so_far, result = values[0], 0 + for i in range(1, len(values)): + result = max(result, max_so_far+values[i]-i) + max_so_far = max(max_so_far, values[i]+i) + return result + + +def main(): + values = [8, 1, 5, 2, 6] + assert Solution().maxScoreSightseeingPair(values) == 11 + + values = [1, 2] + assert Solution().maxScoreSightseeingPair(values) == 2 + + +if __name__ == '__main__': + main() diff --git a/2024-12-December-LeetCoding-Challenge/README.md b/2024-12-December-LeetCoding-Challenge/README.md index 75561f0..ec8c166 100644 --- a/2024-12-December-LeetCoding-Challenge/README.md +++ b/2024-12-December-LeetCoding-Challenge/README.md @@ -29,7 +29,7 @@ | December 24 | [3203. Find Minimum Diameter After Merging Two Trees](https://leetcode.com/problems/find-minimum-diameter-after-merging-two-trees/) | Hard | Unsolved | | December 25 | [515. Find Largest Value in Each Tree Row](https://leetcode.com/problems/find-largest-value-in-each-tree-row/) | Medium | Solved | | December 26 | [494. Target Sum](https://leetcode.com/problems/target-sum/) | Medium | Solved | -| December 27 | []() | | | +| December 27 | [1014. Best Sightseeing Pair](https://leetcode.com/problems/best-sightseeing-pair/) | Medium | Unsolved | | December 28 | []() | | | | December 29 | []() | | | | December 30 | []() | | | @@ -39,5 +39,5 @@ | Level | Problems | Solved | Unsolved | | --- | --- | --- | --- | | Easy | 5 | 5 | 0 | -| Medium | 18 | 12 | 6 | +| Medium | 19 | 12 | 7 | | Hard | 3 | 0 | 3 |