Total minutes scheduled
A weekly grid lists every shift as a start and end in minutes past midnight. Add up the committed hours.
- A shift always ends after it starts.
- An empty grid is an empty week: zero minutes.
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.
Where you start
func shiftTotal(shifts []Shift) int {
}
Worked examples
| Call | Result |
|---|---|
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
}