Drill

ProblemsJava › machines

Average downtime per stop

mediummachinesArraysMathJava

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

meanDowntime(durations: list<int>) → int

Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

int meanDowntime(List<Integer> durations) {
    
}

Worked examples

CallResult
meanDowntime(Main.<Integer>ls(10, 20, 30))20
meanDowntime(Main.<Integer>ls(5, 6))5
meanDowntime(Main.<Integer>ls())0
meanDowntime(Main.<Integer>ls(100))100

Hint

Sum then divide by the length; guard the empty case.

Reference solution in Java
int meanDowntime(List<Integer> durations) {
    if (durations.isEmpty()) return 0;
    int sum = 0;
    for (int d : durations) sum += d;
    return sum / durations.size();
}

The same problem in another language

More machines problems in Java