Drill

ProblemsGo › machines

Total minutes the line was down

mediummachinesIntervalsArraysGo

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

Go 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

func downtimeTotal(blocks []Block) int {
	
}

Worked examples

CallResult
downtimeTotal([]Block{Block{Start: 0, End: 60}, Block{Start: 120, End: 200}})140
downtimeTotal([]Block{Block{Start: 0, End: 30}})30
downtimeTotal([]Block{})0
downtimeTotal([]Block{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 Go
func downtimeTotal(blocks []Block) int {
	total := 0
	for _, b := range blocks {
		total += b.End - b.Start
	}
	return total
}

The same problem in another language

More machines problems in Go