Problems › Python › 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.
understaffed_slots(demand: list<int>, staffing: list<int>) → int
Where you start
def understaffed_slots(demand: list[int], staffing: list[int]) -> int:
Worked examples
| Call | Result |
|---|---|
understaffed_slots([3, 2, 5], [3, 1, 5]) | 1 |
understaffed_slots([1, 1], [1, 2]) | 0 |
understaffed_slots([], []) | 0 |
understaffed_slots([4, 4], [3, 3]) | 2 |
Hint
Count where demand beats staffing.
Reference solution in Python
def understaffed_slots(demand: list[int], staffing: list[int]) -> int:
return sum(1 for d, s in zip(demand, staffing) if d > s)