Drill

ProblemsTypeScript › scheduling

Labour cost for the roster

mediumschedulingTypeScript

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

Solve it in the editor →

Where you start

function labourCost(shifts: Shift[], ratePerHour: number): number {
  
}

Worked examples

CallResult
labourCost([{"start":480,"end":900},{"start":900,"end":1080}], 2000)20000
labourCost([{"start":0,"end":30}], 2000)1000
labourCost([{"start":0,"end":0}], 5000)0
labourCost([], 1000)0

Hint

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

Reference solution in TypeScript
function labourCost(shifts: Shift[], ratePerHour: number): number {
  let mins = 0;
  for (const s of shifts) mins += s.end - s.start;
  return Math.floor((mins * ratePerHour) / 60);
}

The same problem in another language

More scheduling problems in TypeScript