Drill

ProblemsJava › machines

Total minutes the line was down

mediummachinesIntervalsArraysJava

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

downtimeTotal(blocks: list<Block>) → 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 downtimeTotal(List<Block> blocks) {
    
}

Worked examples

CallResult
downtimeTotal(Main.<Block>ls(new Block(0, 60), new Block(120, 200)))140
downtimeTotal(Main.<Block>ls(new Block(0, 30)))30
downtimeTotal(Main.<Block>ls())0
downtimeTotal(Main.<Block>ls(new Block(5, 10), new Block(20, 25), new Block(100, 130)))40

Hint

Add up (end - start) across every block.

Reference solution in Java
int downtimeTotal(List<Block> blocks) {
    int total = 0;
    for (Block b : blocks) total += b.end - b.start;
    return total;
}

The same problem in another language

More machines problems in Java