Drill

ProblemsPython › machines

Average downtime per stop

mediummachinesPython

Support wants a single number for "how long stops usually take", averaged over every recorded event.

mean_downtime(durations: list<int>) → int

Solve it in the editor →

Where you start

def mean_downtime(durations: list[int]) -> int:
    

Worked examples

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

The same problem in another language

More machines problems in Python