Problems › TypeScript › scheduling
How many slots are understaffed
Demand lists the staff needed per slot and staffing lists who is actually on. Count the slots that fall short.
- An exact match is fine.
- The lists are parallel, same length.
understaffedSlots(demand: list<int>, staffing: list<int>) → int
Where you start
function understaffedSlots(demand: number[], staffing: number[]): number {
}
Worked examples
| Call | Result |
|---|---|
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;
}