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
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.
Where you start
public int UnderstaffedSlots(List<int> demand, List<int> staffing) {
}
Worked examples
| Call | Result |
|---|---|
UnderstaffedSlots(new List<int> { 3, 2, 5 }, new List<int> { 3, 1, 5 }) | 1 |
UnderstaffedSlots(new List<int> { 1, 1 }, new List<int> { 1, 2 }) | 0 |
UnderstaffedSlots(new List<int> { }, new List<int> { }) | 0 |
UnderstaffedSlots(new List<int> { 4, 4 }, new List<int> { 3, 3 }) | 2 |
Hint
Count where demand beats staffing.
Reference solution in C#
public int UnderstaffedSlots(List<int> demand, List<int> staffing) {
int n = 0;
for (int i = 0; i < demand.Count; i++) if (demand[i] > staffing[i]) n++;
return n;
}