Drill

ProblemsPython › logistics

Which trucks are overloaded

easylogisticsPython

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

over_capacity(loads: list<int>, capacity: list<int>) → int

Solve it in the editor →

Where you start

def over_capacity(loads: list[int], capacity: list[int]) -> int:
    

Worked examples

CallResult
over_capacity([10, 20, 30], [8, 20, 40])1
over_capacity([1, 2], [9, 9])0
over_capacity([10, 10], [4, 4])2
over_capacity([], [])0

Hint

Iterate the indices and compare.

Reference solution in Python
def over_capacity(loads: list[int], capacity: list[int]) -> int:
    return sum(1 for a, b in zip(loads, capacity) if a > b)

The same problem in another language

More logistics problems in Python