Problems › TypeScript › logistics
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.
overCapacity(loads: list<int>, capacity: list<int>) → int
Where you start
function overCapacity(loads: number[], capacity: number[]): number {
}
Worked examples
| Call | Result |
|---|---|
overCapacity([10,20,30], [8,20,40]) | 1 |
overCapacity([1,2], [9,9]) | 0 |
overCapacity([10,10], [4,4]) | 2 |
overCapacity([], []) | 0 |
Hint
Iterate the indices and compare.
Reference solution in TypeScript
function overCapacity(loads: number[], capacity: number[]): number {
let n = 0;
for (let i = 0; i < loads.length; i++) if (loads[i] > capacity[i]) n++;
return n;
}