Coding problem
Can the parcels be shipped?
The task
Before a van leaves, the warehouse checks its batch of parcels.
Complete Check(List<Parcel> parcels). Parcel is a record with an Id, its WeightKg and whether it is Labelled. Return a ShipCheck: Unlabelled is the number of parcels that are not labelled, and Overweight is the number of parcels heavier than 30 kg (exactly 30 kg is allowed). CanShip is true only when the batch has at least one parcel, every parcel is labelled and no parcel is overweight. A parcel that is unlabelled and overweight counts in both numbers. The list and its parcels are never null.
Signature
public record Parcel(string Id, decimal WeightKg, bool Labelled); public record ShipCheck(bool CanShip, int Unlabelled, int Overweight); public static ShipCheck Check(List<Parcel> parcels)
Examples
[("p1", 12.5, true), ("p2", 31, true), ("p3", 4, false)]→(false, 1, 1). p3 has no label and p2 is over 30 kg.[]→(false, 0, 0). An empty batch has nothing to ship.
Limits: Up to 500,000 parcels.
The tests check: an empty batch, a good batch, exactly 30 kg, just over 30 kg, one unlabelled parcel stopping the batch, a parcel that is both unlabelled and overweight, and 500,000 parcels in time.
Hints
The solution opens by itself when all tests pass. You remember more if you try first.
Sign in to see the solutionYour code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public record Parcel(string Id, decimal WeightKg, bool Labelled);
public record ShipCheck(bool CanShip, int Unlabelled, int Overweight);
public static class Solution
{
// Counts the unlabelled and overweight parcels, and says whether the batch can ship.
public static ShipCheck Check(List<Parcel> parcels)
{
throw new NotImplementedException();
}
}Sign in to run and submit your code. It stays here while you do.