Skip to content
kwitsy Start a group

Settle a group with the fewest payments

Work out each person's net balance, then find as many separate subgroups as possible whose balances cancel out exactly. A group of n people with a balance never needs more than n − 1 payments, and every extra subgroup that cancels saves one more.

Updated

Step 1: what are net balances?

A person's net balance is what they paid minus their share of everything. Positive means the group owes them, negative means they owe. The nets of a group always add up to zero, so only the nets matter for settling, not who paid for which expense.

Example: five people after a trip
PersonNet (EUR)
Ana+40.00
Ben+30.00
Chiara+20.00
Dan−50.00
Eva−40.00

Step 2: why the usual method can take an extra payment

The common hand method is greedy: the biggest debtor pays the biggest creditor as much as possible, then repeat. For the group above that takes 4 payments:

  1. Dan pays Ana 40.00 EUR
  2. Eva pays Ben 30.00 EUR
  3. Eva pays Chiara 10.00 EUR
  4. Dan pays Chiara 10.00 EUR

Step 3: find subgroups that cancel out

Each subgroup whose nets add up to zero can be settled on its own with one payment fewer than its size. So the minimum number of payments is n − k, where k is the largest number of separate zero-sum subgroups. Here Ana and Eva cancel (+40, −40) and Ben, Chiara and Dan cancel (+30, +20, −50): k = 2, so 5 − 2 = 3 payments.

  1. Eva pays Ana 40.00 EUR
  2. Dan pays Ben 30.00 EUR
  3. Dan pays Chiara 20.00 EUR

This is the plan Kwitsy's settle-up code produces for these balances.

How does Kwitsy compute it?

  • Drop everyone whose net is zero; call the rest n.
  • For n up to 16, compute the exact minimum: a dynamic programme over all 2n subgroups finds the largest number of separate zero-sum subgroups, then settles inside each one.
  • Above 16 people with a balance, use the greedy method, which never needs more than n − 1 payments.
  • People are always sorted the same way first, so every device shows the same plan.

Kwitsy's property tests check, over 1,000 random cases per property, that after the plan every balance is zero, nobody both pays and receives, and for up to 8 people the count equals a brute-force minimum. "Simplify debts" can be turned off to see who owes whom directly instead.

Questions and answers

What is the minimum number of payments to settle a group?

n − k, where n is the number of people with a non-zero balance and k is the largest number of separate subgroups whose balances add up to zero. It is never more than n − 1.

Is the greedy method always optimal?

No. Matching the biggest debtor with the biggest creditor never needs more than n − 1 payments, but it can miss subgroups that cancel out and take one or more extra payments.