go: add «1701. Average Waiting Time»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
a0c53fcdeb
commit
8198249ac5
1 changed files with 15 additions and 0 deletions
15
go/average-waiting-time.go
Normal file
15
go/average-waiting-time.go
Normal 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))
|
||||||
|
}
|
Loading…
Reference in a new issue