Back to problems

Optimal Account Balancing (LeetCode 465)

Algorithm · Salesforce · Hard

After a group outing, friends keep a record of who paid for whom. You are given a list transactions, where each element is a triple [a, b, m] that represents person a giving m dollars to person b. As a result of these payments, some people end up with a net credit (they are owed money) and others with a net debit (they owe money). To settle everything, the group can make direct transfers – any person can pay any other person any amount. The objective is to find the fewest…

Checking your access…