Drill

ProblemsJava › scheduling

How many slots are understaffed

easyschedulingArraysJava

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

Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

int understaffedSlots(List<Integer> demand, List<Integer> staffing) {
    
}

Worked examples

CallResult
understaffedSlots(Main.<Integer>ls(3, 2, 5), Main.<Integer>ls(3, 1, 5))1
understaffedSlots(Main.<Integer>ls(1, 1), Main.<Integer>ls(1, 2))0
understaffedSlots(Main.<Integer>ls(), Main.<Integer>ls())0
understaffedSlots(Main.<Integer>ls(4, 4), Main.<Integer>ls(3, 3))2

Hint

Count where demand beats staffing.

Reference solution in Java
int understaffedSlots(List<Integer> demand, List<Integer> staffing) {
    int n = 0;
    for (int i = 0; i < demand.size(); i++) if (demand.get(i) > staffing.get(i)) n++;
    return n;
}

The same problem in another language

More scheduling problems in Java