Drill

ProblemsGo › logistics

Which trucks are overloaded

easylogisticsArraysGo

A dispatch list pairs each truck with its load and its capacity. Count how many trucks are carrying more than their capacity.

overCapacity(loads: list<int>, capacity: 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 overCapacity(loads []int, capacity []int) int {
	
}

Worked examples

CallResult
overCapacity([]int{10, 20, 30}, []int{8, 20, 40})1
overCapacity([]int{1, 2}, []int{9, 9})0
overCapacity([]int{10, 10}, []int{4, 4})2
overCapacity([]int{}, []int{})0

Hint

Iterate the indices and compare.

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

The same problem in another language

More logistics problems in Go