From 8198249ac5bc41f9aaef31d0df3b8f0a372f593a Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 9 Jul 2024 09:52:12 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB1701.=20Average=20Waiting=20T?= =?UTF-8?q?ime=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/average-waiting-time.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 go/average-waiting-time.go diff --git a/go/average-waiting-time.go b/go/average-waiting-time.go new file mode 100644 index 0000000..14b59d4 --- /dev/null +++ b/go/average-waiting-time.go @@ -0,0 +1,15 @@ +package main + +func averageWaitingTime(customers [][]int) float64 { + waitingTime := 0 + + idleAt := 0 + for _, customer := range customers { + arrives, length := customer[0], customer[1] + + idleAt = max(idleAt, arrives) + length + waitingTime += idleAt - arrives + } + + return float64(waitingTime) / float64(len(customers)) +}