Drill

ProblemsPython › logistics

Parcel discount band

mediumlogisticsPython

A monthly contract discounts each parcel once the month's total reaches a threshold: every parcel from then on ships 15% cheaper.

bulk_discount_band(parcel_costs: list<int>, threshold: int) → int

Solve it in the editor →

Where you start

def bulk_discount_band(parcel_costs: list[int], threshold: int) -> int:
    

Worked examples

CallResult
bulk_discount_band([100, 100, 100, 100], 250)370
bulk_discount_band([100, 100], 200)185
bulk_discount_band([100, 100, 100], 1000)300
bulk_discount_band([], 0)0

Hint

Walk the values; once the running total crosses the threshold everything from that parcel on is discounted.

Reference solution in Python
def bulk_discount_band(parcel_costs: list[int], threshold: int) -> int:
    total, running = 0, 0
    for cost in parcel_costs:
        running += cost
        total += (cost * 85 // 100) if running >= threshold else cost
    return total

The same problem in another language

More logistics problems in Python