FreeCareerPath
Debug the CodebaseMedium

Fix: The Invoice That Does Not Balance

An invoicing service splits a total across several line items and then verifies the parts sum back to the whole. It fails intermittently in production with "invoice does not balance", and nobody can reproduce it locally with round numbers. `split_amount(total_cents, weights)` distributes `total_cents` proportionally across `weights` and must return integers that sum to **exactly** `total_cents`. The code below looks reasonable and is wrong. Find the bug and fix it — the hidden tests include the cases production actually hit.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Fix: The Invoice That Does Not Balance" are saved to your account — logging in takes a few seconds.

Fix: The Invoice That Does Not Balance — FreeCareerPath