Drill

ProblemsC# › machines

Average downtime per stop

mediummachinesArraysMathC#

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

MeanDowntime(durations: list<int>) → int

C# 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

public int MeanDowntime(List<int> durations) {
    
}

Worked examples

CallResult
MeanDowntime(new List<int> { 10, 20, 30 })20
MeanDowntime(new List<int> { 5, 6 })5
MeanDowntime(new List<int> { })0
MeanDowntime(new List<int> { 100 })100

Hint

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

Reference solution in C#
public int MeanDowntime(List<int> durations) {
    if (durations.Count == 0) return 0;
    int sum = 0;
    foreach (int d in durations) sum += d;
    return sum / durations.Count;
}

The same problem in another language

More machines problems in C#