Drill

ProblemsC++ › scheduling

How many slots are understaffed

easyschedulingArraysC++

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

C++ 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(std::vector<int> demand, std::vector<int> staffing) {
    
}

Worked examples

CallResult
understaffedSlots(std::vector<int>{3, 2, 5}, std::vector<int>{3, 1, 5})1
understaffedSlots(std::vector<int>{1, 1}, std::vector<int>{1, 2})0
understaffedSlots(std::vector<int>{}, std::vector<int>{})0
understaffedSlots(std::vector<int>{4, 4}, std::vector<int>{3, 3})2

Hint

Count where demand beats staffing.

Reference solution in C++
int understaffedSlots(std::vector<int> demand, std::vector<int> staffing) {
    int n = 0;
    for (size_t i = 0; i < demand.size(); i++) if (demand[i] > staffing[i]) n++;
    return n;
}

The same problem in another language

More scheduling problems in C++