Labour cost for the roster
A shift costs its staffed hours at ratePerHour (minor units per hour). Hours come from minute spans, prorated exactly.
- Pay = minutes ÷ 60 × rate, rounded down to whole minor units.
- A shift that lasts zero minutes costs nothing.
labourCost(shifts: list<Shift>, ratePerHour: int) → 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 labourCost(shifts []Shift, ratePerHour int) int {
}
Worked examples
| Call | Result |
|---|---|
labourCost([]Shift{Shift{Start: 480, End: 900}, Shift{Start: 900, End: 1080}}, 2000) | 20000 |
labourCost([]Shift{Shift{Start: 0, End: 30}}, 2000) | 1000 |
labourCost([]Shift{Shift{Start: 0, End: 0}}, 5000) | 0 |
labourCost([]Shift{}, 1000) | 0 |
Hint
Sum (end - start) × rate, then divide by 60 once.
Reference solution in Go
func labourCost(shifts []Shift, ratePerHour int) int {
mins := 0
for _, s := range shifts {
mins += s.End - s.Start
}
return mins * ratePerHour / 60
}