Drill

ProblemsGo › scheduling

Total minutes scheduled

easyschedulingArraysIntervalsGo

A weekly grid lists every shift as a start and end in minutes past midnight. Add up the committed hours.

shiftTotal(shifts: list<Shift>) → 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 shiftTotal(shifts []Shift) int {
	
}

Worked examples

CallResult
shiftTotal([]Shift{Shift{Start: 480, End: 900}, Shift{Start: 900, End: 1080}})600
shiftTotal([]Shift{Shift{Start: 0, End: 1440}})1440
shiftTotal([]Shift{})0
shiftTotal([]Shift{Shift{Start: 600, End: 600}})0

Hint

Sum of (end - start).

Reference solution in Go
func shiftTotal(shifts []Shift) int {
	total := 0
	for _, s := range shifts {
		total += s.End - s.Start
	}
	return total
}

The same problem in another language

More scheduling problems in Go