Skip to content
Preptima
mediumCodingDesignMidSeniorStaff

Build a shared-expense tracker. Three people split a bill of ten pounds evenly - write the classes, and tell me where the missing penny goes.

A Splitwise-style machine coding answer turns on one invariant: the shares of an expense must sum to the expense total exactly, in every currency, forever. That forces money into integer minor units and forces a stated rule for allocating the remainder.

6 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

In a Splitwise-style machine coding round, the core invariant is that every expense split must add back to the exact expense total. Store money as integer minor units or an exact decimal type, never double, and allocate any leftover penny by a deterministic rule. The strongest design keeps balances derived from expenses and validates the sum-to-total invariant in one place.

Keep machine coding explicit in the answer because that is the concept the interviewer is actually trying to test. A good machine coding explanation names the trade-off, the failure mode, and the evidence you would use before choosing.

Was this answer helpful?

Likely follow-ups

  • The same three people split fifty bills. How do you stop one of them always paying the extra penny?
  • Somebody edits an expense from last month. What happens to the balances, and to a settlement already made?
  • Two participants are in different currencies. What do you store on the expense, and what do you refuse to compute?
  • Your settlement suggests four transfers and a participant finds three. Is your algorithm wrong?

Related questions