LeetCode/go/average-waiting-time.go
Matej Focko 8198249ac5
go: add «1701. Average Waiting Time»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-07-09 09:52:12 +02:00

15 lines
320 B
Go

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