Drill

ProblemsPython › scheduling

Labour cost for the roster

mediumschedulingPython

A shift costs its staffed hours at ratePerHour (minor units per hour). Hours come from minute spans, prorated exactly.

labour_cost(shifts: list<Shift>, rate_per_hour: int) → int

Solve it in the editor →

Where you start

def labour_cost(shifts: list[Shift], rate_per_hour: int) -> int:
    

Worked examples

CallResult
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

The same problem in another language

More scheduling problems in Python