Drill

ProblemsGo › scheduling

How many slots are understaffed

easyschedulingArraysGo

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

Go 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

func understaffedSlots(demand []int, staffing []int) int {
	
}

Worked examples

CallResult
understaffedSlots([]int{3, 2, 5}, []int{3, 1, 5})1
understaffedSlots([]int{1, 1}, []int{1, 2})0
understaffedSlots([]int{}, []int{})0
understaffedSlots([]int{4, 4}, []int{3, 3})2

Hint

Count where demand beats staffing.

Reference solution in Go
func understaffedSlots(demand []int, staffing []int) int {
	n := 0
	for i := range demand {
		if demand[i] > staffing[i] {
			n++
		}
	}
	return n
}

The same problem in another language

More scheduling problems in Go