Drill

ProblemsTypeScript › scheduling

How many slots are understaffed

easyschedulingTypeScript

Demand lists the staff needed per slot and staffing lists who is actually on. Count the slots that fall short.

understaffedSlots(demand: list<int>, staffing: list<int>) → int

Solve it in the editor →

Where you start

function understaffedSlots(demand: number[], staffing: number[]): number {
  
}

Worked examples

CallResult
understaffedSlots([3,2,5], [3,1,5])1
understaffedSlots([1,1], [1,2])0
understaffedSlots([], [])0
understaffedSlots([4,4], [3,3])2

Hint

Count where demand beats staffing.

Reference solution in TypeScript
function understaffedSlots(demand: number[], staffing: number[]): number {
  let n = 0;
  for (let i = 0; i < demand.length; i++) if (demand[i] > staffing[i]) n++;
  return n;
}

The same problem in another language

More scheduling problems in TypeScript