Drill

ProblemsTypeScript › machines

Total minutes the line was down

mediummachinesTypeScript

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

Solve it in the editor →

Where you start

function downtimeTotal(blocks: Block[]): number {
  
}

Worked examples

CallResult
downtimeTotal([{"start":0,"end":60},{"start":120,"end":200}])140
downtimeTotal([{"start":0,"end":30}])30
downtimeTotal([])0
downtimeTotal([{"start":5,"end":10},{"start":20,"end":25},{"start":100,"end":130}])40

Hint

Add up (end - start) across every block.

Reference solution in TypeScript
function downtimeTotal(blocks: Block[]): number {
  let total = 0;
  for (const b of blocks) total += b.end - b.start;
  return total;
}

The same problem in another language

More machines problems in TypeScript