Drill

ProblemsTypeScript › logistics

Which trucks are overloaded

easylogisticsTypeScript

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

Solve it in the editor →

Where you start

function overCapacity(loads: number[], capacity: number[]): number {
  
}

Worked examples

CallResult
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;
}

The same problem in another language

More logistics problems in TypeScript