Drill

ProblemsJava › machines

Total hours a machine ran

mediummachinesIntervalsArraysMathJava

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

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

Worked examples

CallResult
runHours(Main.<Operation>ls(new Operation(0, 60), new Operation(600, 900)))6
runHours(Main.<Operation>ls(new Operation(540, 600)))1
runHours(Main.<Operation>ls())0
runHours(Main.<Operation>ls(new Operation(0, 30)))0

Hint

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

Reference solution in Java
int runHours(List<Operation> operations) {
    int total = 0;
    for (Operation o : operations) total += o.end - o.start;
    return total / 60;
}

The same problem in another language

More machines problems in Java