Algorithm · Pinterest · Medium
You are given transactions in the form transactions[k] = {from, to, amount}. Produce any collection of repayments, paybacks[m] = {payer, receiver, amount}, such that every participant finishes with a net balance of zero. You are not required to use the fewest repayment transactions; any valid settlement is acceptable. Example D paid a total of 10, while E and F each receive a net amount of 5, so these two paybacks settle all balances.
Checking your access…