Drill

ProblemsJavaScript › logistics

Which trucks are overloaded

easylogisticsJavaScript

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, capacity) {
  
}

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 JavaScript
function overCapacity(loads, capacity) {
  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 JavaScript