Problems › Python › scheduling
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.
labour_cost(shifts: list<Shift>, rate_per_hour: int) → int
Where you start
def labour_cost(shifts: list[Shift], rate_per_hour: int) -> int:
Worked examples
| Call | Result |
|---|---|
labour_cost([Shift(start=480, end=900), Shift(start=900, end=1080)], 2000) | 20000 |
labour_cost([Shift(start=0, end=30)], 2000) | 1000 |
labour_cost([Shift(start=0, end=0)], 5000) | 0 |
labour_cost([], 1000) | 0 |
Hint
Sum (end - start) × rate, then divide by 60 once.
Reference solution in Python
def labour_cost(shifts: list[Shift], rate_per_hour: int) -> int:
mins = sum(s.end - s.start for s in shifts)
return mins * rate_per_hour // 60