Total minutes the line was down
A shift log stores each stop as a block of start and end minutes. Sum the length of every block to get total downtime.
- A block contributes its end minus start.
- Block never overlap and every end is after its start.
downtime_total(blocks: list<Block>) → int
Where you start
def downtime_total(blocks: list[Block]) -> int:
Worked examples
| Call | Result |
|---|---|
downtime_total([Block(start=0, end=60), Block(start=120, end=200)]) | 140 |
downtime_total([Block(start=0, end=30)]) | 30 |
downtime_total([]) | 0 |
downtime_total([Block(start=5, end=10), Block(start=20, end=25), Block(start=100, end=130)]) | 40 |
Hint
Add up (end - start) across every block.
Reference solution in Python
def downtime_total(blocks: list[Block]) -> int:
return sum(b.end - b.start for b in blocks)