Drill

ProblemsPython › machines

Total minutes the line was down

mediummachinesPython

A shift log stores each stop as a block of start and end minutes. Sum the length of every block to get total downtime.

downtime_total(blocks: list<Block>) → int

Solve it in the editor →

Where you start

def downtime_total(blocks: list[Block]) -> int:
    

Worked examples

CallResult
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)

The same problem in another language

More machines problems in Python