Drill

ProblemsC# › logistics

Which trucks are overloaded

easylogisticsArraysC#

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

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int OverCapacity(List<int> loads, List<int> capacity) {
    
}

Worked examples

CallResult
OverCapacity(new List<int> { 10, 20, 30 }, new List<int> { 8, 20, 40 })1
OverCapacity(new List<int> { 1, 2 }, new List<int> { 9, 9 })0
OverCapacity(new List<int> { 10, 10 }, new List<int> { 4, 4 })2
OverCapacity(new List<int> { }, new List<int> { })0

Hint

Iterate the indices and compare.

Reference solution in C#
public int OverCapacity(List<int> loads, List<int> capacity) {
    int n = 0;
    for (int i = 0; i < loads.Count; i++) if (loads[i] > capacity[i]) n++;
    return n;
}

The same problem in another language

More logistics problems in C#