Total hours a machine ran
A machine records operations as start and end minutes past midnight. Convert the whole running total into whole hours.
- Each operation adds end minus start minutes.
- Total is reported in whole hours, truncated down.
- Operations never cross midnight and every end is after its start.
run_hours(operations: list<Operation>) → int
Where you start
def run_hours(operations: list[Operation]) -> int:
Worked examples
| Call | Result |
|---|---|
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