Drill

ProblemsPython › machines

Total hours a machine ran

mediummachinesPython

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

run_hours(operations: list<Operation>) → int

Solve it in the editor →

Where you start

def run_hours(operations: list[Operation]) -> int:
    

Worked examples

CallResult
run_hours([Operation(start=0, end=60), Operation(start=600, end=900)])6
run_hours([Operation(start=540, end=600)])1
run_hours([])0
run_hours([Operation(start=0, end=30)])0

Hint

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

Reference solution in Python
def run_hours(operations: list[Operation]) -> int:
    return sum(o.end - o.start for o in operations) // 60

The same problem in another language

More machines problems in Python