What does this parcel cost to send
A courier prices every parcel as: the first five kilograms cost 300 (minor units) and each further kilogram adds 60.
- A parcel at or under five kilograms always costs 300.
- Every whole kilogram over five adds 60; there are no fractions here.
- A parcel cannot weigh negative kilograms: return 0 for bad input.
ParcelCost(weight: 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.
Where you start
public int ParcelCost(int weight) {
}
Worked examples
| Call | Result |
|---|---|
ParcelCost(3) | 300 |
ParcelCost(5) | 300 |
ParcelCost(6) | 360 |
ParcelCost(10) | 600 |
Hint
Subtract the free five, multiply what is left, and add the base.
Reference solution in C#
public int ParcelCost(int weight) {
if (weight < 0) return 0;
return 300 + Math.Max(0, weight - 5) * 60;
}