From 945eef30d175f434bf48c27671e9feb0291aead0 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 27 Dec 2024 11:07:01 +0100 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB1014.=20Best=20Sightseeing=20?= =?UTF-8?q?Pair=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/best-sightseeing-pair/ Signed-off-by: Matej Focko --- go/best-sightseeing-pair.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 go/best-sightseeing-pair.go diff --git a/go/best-sightseeing-pair.go b/go/best-sightseeing-pair.go new file mode 100644 index 0000000..cc370f6 --- /dev/null +++ b/go/best-sightseeing-pair.go @@ -0,0 +1,15 @@ +package main + +func maxScoreSightseeingPair(values []int) int { + maxLeft := values[0] + + maxScore := 0 + for i := 1; i < len(values); i++ { + rightScore := values[i] - i + maxScore = max(maxScore, maxLeft+rightScore) + + maxLeft = max(maxLeft, values[i]+i) + } + + return maxScore +}