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)) +}