SoloMedium12m

The Discount Split That Created a Cent

### P2 · A coupon that does not reconcile Checkout applies a 100-cent coupon across three eligible lines, then rounds each line independently. The invoice reports 101 cents of discounts.

Your task: Fix only allocate_discount() in allocation.py. Use exact integer quota arithmetic and the specified largest-remainder policy. Allocate leftover cents by descending fractional remainder, breaking ties by ascending line ID. Preserve every input line and conserve the coupon total.

Investigate: Run python monitor.py, then python -m pytest -v. The starter is intentionally wrong. Handle zero amounts, input permutations and integers beyond floating-point precision without looping once per cent. Keep the supplied validation contract. Open a PR against main with your explanation.

Learn: integer division and remainders, deterministic ordering, conservation invariants and regression tests. Python 3.12, standard-library runtime, pinned pytest tools.

The incident is authored. This is a pure allocation-policy exercise, not live checkout, tax or payment-system validation.

Skills you'll prove

pythonalgorithmsinteger-arithmeticlargest-remaindertestingdebuggingbook-vs-prod

Interview Tip

I treated the coupon as one integer budget rather than rounding each line independently. Integer division gave the whole quotas and remainders; a deterministic ordering assigned the few leftover cents. I tested conservation, remainder priority, tied IDs, zero weights, huge integers and input permutations. I distinguished this specified allocation policy from claims of universal fairness.

Browse freely — sign in when you're ready to open a ticket and prove your skills.