Drill

ProblemsPython › scheduling

How many slots are understaffed

easyschedulingPython

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

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

Solve it in the editor →

Where you start

def understaffed_slots(demand: list[int], staffing: list[int]) -> int:
    

Worked examples

CallResult
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)

The same problem in another language

More scheduling problems in Python