Drill

ProblemsPython › logistics

Split a load into the fewest parcels

easylogisticsPython

A warehouse has to ship a totalWeight in parcel boxes that hold at most maxPerBox each. Find how many parcels are needed.

parcel_count(total_weight: int, max_per_box: int) → int

Solve it in the editor →

Where you start

def parcel_count(total_weight: int, max_per_box: int) -> int:
    

Worked examples

CallResult
parcel_count(100, 20)5
parcel_count(101, 20)6
parcel_count(0, 20)0
parcel_count(50, 0)0

Hint

Divide and round up; watch the division-by-zero case first.

Reference solution in Python
def parcel_count(total_weight: int, max_per_box: int) -> int:
    if total_weight <= 0 or max_per_box <= 0:
        return 0
    return (total_weight + max_per_box - 1) // max_per_box

The same problem in another language

More logistics problems in Python