Which trucks are overloaded
A dispatch list pairs each truck with its load and its capacity. Count how many trucks are carrying more than their capacity.
- The two lists are the same length and read like parallel records.
- A load exactly equal to capacity is fine.
over_capacity(loads: list<int>, capacity: list<int>) → int
Where you start
def over_capacity(loads: list[int], capacity: list[int]) -> int:
Worked examples
| Call | Result |
|---|---|
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)