Drill

ProblemsGo › machines

Total hours a machine ran

mediummachinesIntervalsArraysMathGo

A machine records operations as start and end minutes past midnight. Convert the whole running total into whole hours.

runHours(operations: list<Operation>) → 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 runHours(operations []Operation) int {
	
}

Worked examples

CallResult
runHours([]Operation{Operation{Start: 0, End: 60}, Operation{Start: 600, End: 900}})6
runHours([]Operation{Operation{Start: 540, End: 600}})1
runHours([]Operation{})0
runHours([]Operation{Operation{Start: 0, End: 30}})0

Hint

Sum the minute spans, then integer-divide the total by sixty.

Reference solution in Go
func runHours(operations []Operation) int {
	total := 0
	for _, o := range operations {
		total += o.End - o.Start
	}
	return total / 60
}

The same problem in another language

More machines problems in Go