Drill

ProblemsC++ › machines

Total minutes the line was down

mediummachinesIntervalsArraysC++

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

C++ 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(std::vector<Block> blocks) {
    
}

Worked examples

CallResult
downtimeTotal(std::vector<Block>{Block{0, 60}, Block{120, 200}})140
downtimeTotal(std::vector<Block>{Block{0, 30}})30
downtimeTotal(std::vector<Block>{})0
downtimeTotal(std::vector<Block>{Block{5, 10}, Block{20, 25}, Block{100, 130}})40

Hint

Add up (end - start) across every block.

Reference solution in C++
int downtimeTotal(std::vector<Block> blocks) {
    int total = 0;
    for (const auto& b : blocks) total += b.end - b.start;
    return total;
}

The same problem in another language

More machines problems in C++