Drill

ProblemsPython › billing

Refund for partially used service

mediumbillingPython

A customer paid upfront but only used part of the service. Refund the unused portion.

partial_refund(paid: int, used_units: int, unit_price: int) → int

Solve it in the editor →

Where you start

def partial_refund(paid: int, used_units: int, unit_price: int) -> int:
    

Worked examples

CallResult
partial_refund(1000, 40, 10)600
partial_refund(1000, 200, 10)0
partial_refund(500, 0, 50)500
partial_refund(1000, 100, 10)0

Hint

Multiply usage by price, subtract from what was paid, and clamp.

Reference solution in Python
def partial_refund(paid: int, used_units: int, unit_price: int) -> int:
    cost = used_units * unit_price
    return paid - cost if paid > cost else 0

The same problem in another language

More billing problems in Python