Drill

ProblemsC# › scheduling

Labour cost for the roster

mediumschedulingArraysMathC#

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

LabourCost(shifts: list<Shift>, ratePerHour: int) → int

C# 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

public int LabourCost(List<Shift> shifts, int ratePerHour) {
    
}

Worked examples

CallResult
LabourCost(new List<Shift> { new Shift(480, 900), new Shift(900, 1080) }, 2000)20000
LabourCost(new List<Shift> { new Shift(0, 30) }, 2000)1000
LabourCost(new List<Shift> { new Shift(0, 0) }, 5000)0
LabourCost(new List<Shift> { }, 1000)0

Hint

Sum (end - start) × rate, then divide by 60 once.

Reference solution in C#
public int LabourCost(List<Shift> shifts, int ratePerHour) {
    int mins = 0;
    foreach (var s in shifts) mins += s.End - s.Start;
    return (mins * ratePerHour) / 60;
}

The same problem in another language

More scheduling problems in C#