Atlys's expense-splitter practice asks for a correct debt representation and, in its harder variant, a minimum-transfer solution. Demonstrate the difference between a valid settlement and one that minimizes transaction count.
What to prepare for Atlys
Atlys documents application state and refund tracking. Use this context to discuss money records and replay as a separate follow-up. The expense ledger is fictional. Atlys cancellation and refund status
Build balances before choosing transfers
A pays 90 units for A, B and C equally. Balances in credit notation are A +60, B -30 and C -30. Two transfers to A settle the group. Use integer minor units and agree how to allocate any remainder when a split cannot be exact. Related PracHub practice
Compute one signed balance per participant with the invariant that balances sum to zero. A debtor-creditor greedy with two heaps can produce a valid settlement, but it does not guarantee the fewest transfers. For a small unsettled group, use backtracking that pairs the first nonzero balance with opposite signs and skips equivalent choices. Explain its exponential worst-case behavior.
Keep history when a payment is reversed
A payment receipt is later refunded. Record a reversing event linked to it rather than deleting the original. Recompute balances deterministically and store a stable client request identity for retries. Test splitting a nondivisible total where ordering the cents differently would affect one participant.
Explain when exact search is valuable
Ask about group size, transfer costs and whether users prefer fewer payments or a restricted set of recipients. Offer a scalable valid solution first and compare it with exact search on small fixtures.