go: add «1701. Average Waiting Time»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-07-09 09:52:12 +02:00
parent a0c53fcdeb
commit 8198249ac5
Signed by: mfocko
SSH key fingerprint: SHA256:5YXD7WbPuK60gxnG6DjAwJiS9+swoWj33/HFu8g8JVo

View file

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