Drill

ProblemsC# › machines

Total hours a machine ran

mediummachinesIntervalsArraysMathC#

A machine records operations as start and end minutes past midnight. Convert the whole running total into whole hours.

RunHours(operations: list<Operation>) → 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 RunHours(List<Operation> operations) {
    
}

Worked examples

CallResult
RunHours(new List<Operation> { new Operation(0, 60), new Operation(600, 900) })6
RunHours(new List<Operation> { new Operation(540, 600) })1
RunHours(new List<Operation> { })0
RunHours(new List<Operation> { new Operation(0, 30) })0

Hint

Sum the minute spans, then integer-divide the total by sixty.

Reference solution in C#
public int RunHours(List<Operation> operations) {
    int total = 0;
    foreach (var o in operations) total += o.End - o.Start;
    return total / 60;
}

The same problem in another language

More machines problems in C#