Preparing your design workspace

Loading the problem and your saved attempt…

Design a Shared Expense Splitting Service

Model groups, expenses, exact split strategies, immutable postings, balances, and valid versus minimum-transaction settlement plans.

For this exercise, assume users form groups and record one-currency expenses paid by one member for a non-empty set of participants. An expense uses exactly one split policy: equal shares, exact integer minor-unit amounts, or integer percentages totaling 100.

The policy must allocate the full amount deterministically, including any rounding remainder. Posting an expense creates immutable balanced ledger entries; editing means reversing the prior expense and posting a replacement. Users can inspect pairwise expense history and group net balances.

A recorded settlement transfers a positive integer minor-unit amount from a member with a negative group net balance to a member with a positive group net balance; the amount cannot exceed either member's remaining absolute net position, and the selected transfer does not need to follow a historical pairwise expense edge.

Every state-changing command carries an idempotency key and expected group version; exact retries recover the stored result and stale commands conflict.

The source-reported settle() and settle_optimally() operations are read-only: settle() returns one valid transfer plan and its transaction count, while settle_optimally() returns a valid plan using the minimum possible number of transfers.

Exact optimal planning supports at most 12 members with nonzero net balances and returns a typed limit outcome above that bound. Recording a chosen plan transfer remains a separate versioned settlement command. Currency conversion, payment-provider integration, recurring expenses, and tax are outside scope.