Average downtime per stop
Support wants a single number for "how long stops usually take", averaged over every recorded event.
- The average is the total duration divided by the count, truncated down.
- With no events at all the average is treated as zero.
mean_downtime(durations: list<int>) → int
Where you start
def mean_downtime(durations: list[int]) -> int:
Worked examples
| Call | Result |
|---|---|
mean_downtime([10, 20, 30]) | 20 |
mean_downtime([5, 6]) | 5 |
mean_downtime([]) | 0 |
mean_downtime([100]) | 100 |
Hint
Sum then divide by the length; guard the empty case.
Reference solution in Python
def mean_downtime(durations: list[int]) -> int:
if not durations:
return 0
return sum(durations) // len(durations)