From c56b3d121bdbee3f98850a5ab559bd77a37516e2 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 28 Jun 2024 23:56:30 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB2285.=20Maximum=20Total=20Imp?= =?UTF-8?q?ortance=20of=20Roads=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/maximum-total-importance-of-roads.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 go/maximum-total-importance-of-roads.go diff --git a/go/maximum-total-importance-of-roads.go b/go/maximum-total-importance-of-roads.go new file mode 100644 index 0000000..ae4281a --- /dev/null +++ b/go/maximum-total-importance-of-roads.go @@ -0,0 +1,21 @@ +package main + +import "slices" + +func maximumImportance(n int, roads [][]int) int64 { + degrees := make([]int64, n) + + for _, edge := range roads { + degrees[edge[0]]++ + degrees[edge[1]]++ + } + + slices.Sort(degrees) + + importance := int64(0) + for i, degree := range degrees { + importance += int64(i+1) * degree + } + + return importance +}