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

public int DowntimeTotal(List<Block> blocks) {
    
}

Worked examples

CallResult
DowntimeTotal(new List<Block> { new Block(0, 60), new Block(120, 200) })140
DowntimeTotal(new List<Block> { new Block(0, 30) })30
DowntimeTotal(new List<Block> { })0
DowntimeTotal(new List<Block> { new Block(5, 10), new Block(20, 25), new Block(100, 130) })40

Hint

Add up (end - start) across every block.

Reference solution in C#
public int DowntimeTotal(List<Block> blocks) {
    int total = 0;
    foreach (var b in blocks) total += b.End - b.Start;
    return total;
}

The same problem in another language

More machines problems in C#